CLASS
RenderContext
¶
public class RenderContext<WorkflowType: Workflow>: RenderContextType
RenderContext
is the composition point for the workflow tree.
During a render pass, a workflow may want to defer to a child workflow to render some portion of its content. For example, a workflow that renders to a split-screen view model might delegate to child A for the left side, and child B for the right side view models. Nesting allows for a fractal tree that is constructed out of many small parts.
If a parent wants to delegate to a child workflow, it must first create an instance of that workflow. This can be thought of as the model of the child workflow. It does not contain any active state, it simply contains the data necessary to create or update a workflow node.
The parent then calls render(workflow:outputMap:)
with two values:
- The child workflow.
- A closure that transforms the child’s output events into the parent’s
Event
type so that the parent can respond to events generated by
the child.
If the parent had previously rendered a child of the same type, the existing child workflow node is updated.
If the parent had not rendered a child of the same type in the previous render pass, a new child workflow node is generated.
The infrastructure then performs a render pass on the child to obtain its
Rendering
value, which is then returned to the caller.
Methods¶
makeSink(of:)
¶
public func makeSink<Action>(of actionType: Action.Type) -> Sink<Action> where Action: WorkflowAction, Action.WorkflowType == WorkflowType
Creates a Sink
that can be used to send Action
s.
Sinks are the primary mechanism for feeding State-changing events into the Workflow runtime. Upon receipt of an action, the associated Workflow (node) in the tree will have its State potentially transformed, and then any subsequent Output will be propagated to its parent node until the root of the Workflow tree is reached. At this point the tree will be re-rendered to reflect any State changes that occurred.
- Parameter actionType: The type of Action this Sink may process
- Returns: A Sink capable of relaying
Action
instances to the Workflow runtime
Parameters¶
Name | Description |
---|---|
actionType | The type of Action this Sink may process |
runSideEffect(key:action:)
¶
public func runSideEffect(key: AnyHashable, action: (Lifetime) -> Void)
Execute a side-effect action.
Note that it is a programmer error to run two side-effects with the same key
during the same render pass.
action
will be executed the first time a side-effect is run with a given key
.
runSideEffect
calls with a given key
on subsequent renders are ignored.
If after a render pass, a side-effect with a key
that was previously used is not used,
it’s lifetime ends and the Lifetime
object’s onEnded
closure will be called.
- Parameters:
- key: represents the block of work that needs to be executed.
- action: a block of work that will be executed.
Parameters¶
Name | Description |
---|---|
key | represents the block of work that needs to be executed. |
action | a block of work that will be executed. |