Skip to content
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

[Swift] Rename compose to render and update docs. #301

Merged
merged 1 commit into from
Apr 18, 2019

Conversation

davidapgar
Copy link
Collaborator

Closes #266

@timdonnelly
Copy link
Collaborator

💯

/// screen model.
///
/// - Parameter state: The current state.
/// - Parameter context: The workflow context is the composition point for the workflow tree. To use a nested
/// workflow, instantiate it based on the current state. The newly instantiated workflow is
/// then used to invoke `context.render(_ workflow:)`, which returns the child's `Rendering`
/// type after creating or updating the nested workflow.
func compose(state: State, context: WorkflowContext<Self>) -> Rendering
func render(state: State, context: WorkflowContext<Self>) -> Rendering
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@zach-klippenstein @timdonnelly @bencochran With the name of render here now, does the name of WorkflowContext still make sense?

I am starting to think that RenderContext would be a better type name - as it evokes that this that is context is only valid during the call to render (which has been a usage issue, of capturing and trying to use the context after the render pass is complete).

Not necessary to do it in this change, but wanted to discuss if it makes sense. This came to mind while talking to @bencochran regarding the SideEffects PR, as we now have different contexts, none of which are the "workflow"'s context - more just a context scoped to a single method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would be super happy to rename to RenderContext.

AFAIK we haven't had as much of a problem with people trying to capture it, but if we start to see that one way to discourage it in Kotlin is to make it a receiver on render. It's a somewhat common pattern for FooContext types to be receivers on foo functions in kotlin. We haven't done that yet because we prefer making it clear what you're calling methods on, but the stdlib authors obviously feel differently about this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's only happened a few times, but mostly when someone is trying this out for the first time. The current behavior is "surprising" as a sink created after render is complete doesn't go anywhere, which leads to the behavior where events from a Screen don't get back to the workflow.

I have #269 as an issue to make it assert if an invalid context is used, to at least make it obvious what's happening. But the naming (I would hope) is an extra signal about the scope.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We throw now as well in that case (as of #273). Filed #303 and #304 to track the context rename.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated this PR to also handle the name update to RenderContext as well as the docs.

@davidapgar davidapgar force-pushed the davidapgar/266-rename-compose-to-render branch from 913b98b to 6d80065 Compare April 18, 2019 22:05
@davidapgar davidapgar merged commit db46e44 into master Apr 18, 2019
@AquaGeek AquaGeek deleted the davidapgar/266-rename-compose-to-render branch October 11, 2019 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[swift] Rename compose method and concept in docs to render
3 participants