-
Notifications
You must be signed in to change notification settings - Fork 47
[refactor]: introduce a 'HostContext' for exposing host info through tree #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,6 @@ public protocol WorkflowDebugger { | |
|
||
/// Manages an active workflow hierarchy. | ||
public final class WorkflowHost<WorkflowType: Workflow> { | ||
private let debugger: WorkflowDebugger? | ||
|
||
private let (outputEvent, outputEventObserver) = Signal<WorkflowType.Output, Never>.pipe() | ||
|
||
// @testable | ||
|
@@ -45,6 +43,13 @@ public final class WorkflowHost<WorkflowType: Workflow> { | |
/// as state transitions occur within the hierarchy. | ||
public let rendering: Property<WorkflowType.Rendering> | ||
|
||
/// Context object to pass down to descendant nodes in the tree. | ||
let context: HostContext | ||
|
||
private var debugger: WorkflowDebugger? { | ||
context.debugger | ||
} | ||
|
||
/// Initializes a new host with the given workflow at the root. | ||
/// | ||
/// - Parameter workflow: The root workflow in the hierarchy | ||
|
@@ -56,17 +61,20 @@ public final class WorkflowHost<WorkflowType: Workflow> { | |
observers: [WorkflowObserver] = [], | ||
debugger: WorkflowDebugger? = nil | ||
) { | ||
self.debugger = debugger | ||
|
||
let observer = WorkflowObservation | ||
.sharedObserversInterceptor | ||
.workflowObservers(for: observers) | ||
.chained() | ||
|
||
self.context = HostContext( | ||
observer: observer, | ||
debugger: debugger | ||
) | ||
|
||
self.rootNode = WorkflowNode( | ||
workflow: workflow, | ||
parentSession: nil, | ||
observer: observer | ||
hostContext: context, | ||
parentSession: nil | ||
) | ||
|
||
self.mutableRendering = MutableProperty(rootNode.render()) | ||
|
@@ -115,3 +123,20 @@ public final class WorkflowHost<WorkflowType: Workflow> { | |
outputEvent | ||
} | ||
} | ||
|
||
// MARK: - HostContext | ||
|
||
/// A context object to expose certain root-level information to each node | ||
/// in the Workflow tree. | ||
final class HostContext { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, are you asking why is it a class? assuming 'yes', then it's because i think we will eventually want to allow different parts of the tree to be able to mutate some of its properties and have those changes be visible elsewhere. e.g. you're handling an action and want to remember that 'some node in the tree was invalidated' by the time the root/host has to do the next render. |
||
let observer: WorkflowObserver? | ||
let debugger: WorkflowDebugger? | ||
|
||
init( | ||
observer: WorkflowObserver?, | ||
debugger: WorkflowDebugger? | ||
) { | ||
self.observer = observer | ||
self.debugger = debugger | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this truncated sentence has bothered me for a long time – i think this is probably what it was going to