Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Workflow/Sources/AnyWorkflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extension AnyWorkflow {
/// That type information *is* present in our storage object, however, so we
/// pass the context down to that storage object which will ultimately call
/// through to `context.render(workflow:key:reducer:)`.
internal func render<Parent>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction<Parent>) -> Rendering {
internal func render<Parent, Action>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
return storage.render(context: context, key: key, outputMap: outputMap)
}
}
Expand All @@ -84,7 +84,7 @@ extension AnyWorkflow {
///
/// This type is never used directly.
fileprivate class AnyStorage {
func render<Parent>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction<Parent>) -> Rendering {
func render<Parent, Action>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
fatalError()
}

Expand Down Expand Up @@ -119,8 +119,8 @@ extension AnyWorkflow {
return T.self
}

override func render<Parent>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> AnyWorkflowAction<Parent>) -> Rendering {
let outputMap: (T.Output) -> AnyWorkflowAction<Parent> = { [outputTransform] output in
override func render<Parent, Action>(context: RenderContext<Parent>, key: String, outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
let outputMap: (T.Output) -> Action = { [outputTransform] output in
outputMap(outputTransform(output))
}
let rendering = context.render(workflow: workflow, key: key, outputMap: outputMap)
Expand Down
4 changes: 2 additions & 2 deletions Workflow/Sources/AnyWorkflowConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ extension AnyWorkflowConvertible {
///
/// - Returns: The `Rendering` generated by the workflow.
public func rendered<Parent>(in context: RenderContext<Parent>, key: String = "") -> Rendering where Output: WorkflowAction, Output.WorkflowType == Parent {
return asAnyWorkflow().render(context: context, key: key, outputMap: { AnyWorkflowAction($0) })
return asAnyWorkflow().render(context: context, key: key, outputMap: { $0 })
}

public func rendered<Parent, Action>(in context: RenderContext<Parent>, key: String = "", outputMap: @escaping (Output) -> Action) -> Rendering where Action: WorkflowAction, Action.WorkflowType == Parent {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line below this too, yeah? (github won’t let me comment on collapsed parts of code…)

return asAnyWorkflow().render(context: context, key: key, outputMap: { AnyWorkflowAction(outputMap($0)) })
return asAnyWorkflow().render(context: context, key: key, outputMap: { outputMap($0) })
}

public func rendered<Parent>(in context: RenderContext<Parent>, key: String = "") -> Rendering where Output == AnyWorkflowAction<Parent> {
Expand Down
13 changes: 13 additions & 0 deletions WorkflowTesting/Tests/WorkflowRenderTesterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ final class WorkflowRenderTesterTests: XCTestCase {
.assertNoAction()
}

func test_childWorkflowAction() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this test fail before? I thought this only happened when things got AnyWorkflowd?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test did fail before the fix.

ParentWorkflow(initialText: "hello")
.renderTester()
.expectWorkflow(
type: ChildWorkflow.self,
producingRendering: "olleh",
producingOutput: ChildWorkflow.Output.success
)
.render { rendering in
XCTAssertEqual("olleh", rendering)
}.assert(action: ParentWorkflow.Action.childSuccess)
}

func test_childWorkflowOutput() {
// Test that a child emitting an output is handled as an action by the parent
ParentWorkflow(initialText: "hello")
Expand Down