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

[WIP] Use Observation in WorkflowSwiftUI #260

Conversation

square-tomb
Copy link
Contributor

@square-tomb square-tomb commented Dec 20, 2023

An experimental adaptation of TCA's Observation beta for Workflow.

Development

Since CocoaPods doesn't support SPM package dependencies, you need to manually add package dependencies to Development.xcodeproj after each pod gen.

We currently depend on commit acfbab4290adda4e47026d059db36361958d495c from the observation-beta branch of swift-composable-architecture.

image

For some reason this manually-added dependency works only in sample app targets. In framework targets, import statements yield an error llike:

No such module 'ComposableArchitecture'

`MainScreen` now no longer reacts properly to state changes.
@square-tomb square-tomb changed the title remove ObservedObject property wrapper [WIP] Use Observation in WorkflowSwiftUI Dec 20, 2023
@square-tomb square-tomb force-pushed the tomb/swiftui-testbed-observation branch from f1ae774 to 32668e4 Compare December 21, 2023 23:10
@watt watt mentioned this pull request Mar 15, 2024
@watt watt mentioned this pull request Jun 18, 2024
4 tasks
@square-tomb square-tomb closed this Aug 3, 2024
watt added a commit that referenced this pull request Aug 16, 2024
This is a complete implementation of Workflow-powered SwiftUI views using fine-grained observability to minimize render impact. It's based on the prototype in #276, and @square-tomb's previous prototype #260. Squares can learn more at go/workflow-swiftui.

# Observation

We're depending on Perception, Point-Free's backport of Observation. The approach to observable state is adapted from TCA's approach, with a custom `@ObservableState` macro that endows struct types with a concept of identity.

In workflows, you must annotate your state with `@ObservableState`, and render a type conforming to `ObservableModel`, which wraps your state and sends mutations into the unidirectional flow. There are several built-in conveniences for rendering common cases, or you can create a custom type.

On the view side, your `View` will consume a `Store<Model>` wrapper, which provides access to state, sinks, and any child stores from nested workflows.

To wire things up, you can implement a trivial type conforming to `ObservableScreen` and map your rendering. It's *strongly* recommended to keep these layers separate: render a model, implement a view, and create a screen only where needed. This allows for compositions of workflows and views, which is difficult or impossible if rendering a screen directly.

Check out the new ObservableScreen sample app for complete examples of most concepts being introduced here. I'll also write up an adoption guide that expands on each requirement.

# SwiftPM

The `@ObservableState` macro means we cannot ship `WorkflowSwiftUI` with CocoaPods. For now, this PR only removes WorkflowSwiftUI podspec, but it may be preferable to remove all podpsecs and migrate everything to SwiftPM to reduce the maintenance burden.

To work on WorkflowSwiftUI locally, you can use [xcodegen](https://github.com/yonaskolb/XcodeGen) to create a project, similarly to how `pod gen` works.
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.

1 participant