Skip to content

Commit 876e575

Browse files
authored
[BREAKING CHANGE]: update WorkflowAction API to expose access to Workflow instance values (#349)
this BREAKING change updates the WorkflowAction API to pass through a new parameter in the `apply()` method that allows reading values off the corresponding node's current Workflow instance. the new method signature is: ```swift func apply(toState state: inout State, context: ApplyContext<WorkflowType>) -> Output? ``` which mirrors the `render()` API, but uses a new `ApplyContext` parameter to expose access to the runtime-managed data. the public API for `ApplyContext` exposes a read-only subscript for accessing Workflow values via keypath: ```swift public struct ApplyContext<WorkflowType: Workflow> { public subscript<Value>( workflowValue keyPath: KeyPath<WorkflowType, Value> ) -> Value } ``` --- for reviewing purposes, i'd suggest using the 'commit filter' function to exclude the commit labeled 'AUTOMATED' as that one is essentially just noise where a bunch of new parameters were added. also, there's definitely some more documentation to be written here, but i've currently punted on that somewhat. do feel free to point out places you'd like to see anything specific though.
1 parent e3a157c commit 876e575

File tree

58 files changed

+536
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+536
-93
lines changed

Samples/AsyncWorker/Sources/AsyncWorkerWorkflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension AsyncWorkerWorkflow {
3434

3535
typealias WorkflowType = AsyncWorkerWorkflow
3636

37-
func apply(toState state: inout AsyncWorkerWorkflow.State) -> AsyncWorkerWorkflow.Output? {
37+
func apply(toState state: inout AsyncWorkerWorkflow.State, context: ApplyContext<WorkflowType>) -> AsyncWorkerWorkflow.Output? {
3838
switch self {
3939
// Update state and produce an optional output based on which action was received.
4040
case .fakeNetworkRequestLoaded(let result):

Samples/ObservableComposition/Sources/CounterWorkflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct CounterWorkflow: Workflow {
4949
case increment
5050
case decrement
5151

52-
func apply(toState state: inout CounterWorkflow.State) -> CounterWorkflow.Output? {
52+
func apply(toState state: inout CounterWorkflow.State, context: ApplyContext<WorkflowType>) -> CounterWorkflow.Output? {
5353
switch self {
5454
case .increment:
5555
state.count += state.info.stepSize

Samples/ObservableComposition/Sources/MultiCounterWorkflow.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct MultiCounterWorkflow: Workflow {
3131
struct ResetAction: WorkflowAction {
3232
typealias WorkflowType = MultiCounterWorkflow
3333

34-
func apply(toState state: inout MultiCounterWorkflow.State) -> Never? {
34+
func apply(toState state: inout MultiCounterWorkflow.State, context: ApplyContext<WorkflowType>) -> Never? {
3535
state.resetToken = .init()
3636
return nil
3737
}
@@ -43,7 +43,7 @@ struct MultiCounterWorkflow: Workflow {
4343

4444
case showSum(Bool)
4545

46-
func apply(toState state: inout MultiCounterWorkflow.State) -> Never? {
46+
func apply(toState state: inout MultiCounterWorkflow.State, context: ApplyContext<WorkflowType>) -> Never? {
4747
switch self {
4848
case .showSum(let showSum):
4949
state.showSum = showSum
@@ -58,7 +58,7 @@ struct MultiCounterWorkflow: Workflow {
5858
case addCounter
5959
case removeCounter(UUID)
6060

61-
func apply(toState state: inout MultiCounterWorkflow.State) -> Never? {
61+
func apply(toState state: inout MultiCounterWorkflow.State, context: ApplyContext<WorkflowType>) -> Never? {
6262
switch self {
6363
case .addCounter:
6464
state.addCounter()

Samples/SampleApp/Sources/DemoWorkflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ extension DemoWorkflow {
7676
case refreshComplete(String)
7777
case refreshError(Error)
7878

79-
func apply(toState state: inout DemoWorkflow.State) -> DemoWorkflow.Output? {
79+
func apply(toState state: inout DemoWorkflow.State, context: ApplyContext<WorkflowType>) -> DemoWorkflow.Output? {
8080
switch self {
8181
case .titleButtonTapped:
8282
switch state.colorState {

Samples/SampleApp/Sources/RootWorkflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension RootWorkflow {
4545

4646
case login(name: String)
4747

48-
func apply(toState state: inout RootWorkflow.State) -> RootWorkflow.Output? {
48+
func apply(toState state: inout RootWorkflow.State, context: ApplyContext<WorkflowType>) -> RootWorkflow.Output? {
4949
switch self {
5050
case .login(name: let name):
5151
state = .demo(name: name)

Samples/SampleApp/Sources/WelcomeWorkflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension WelcomeWorkflow {
4646
case nameChanged(String)
4747
case login
4848

49-
func apply(toState state: inout WelcomeWorkflow.State) -> WelcomeWorkflow.Output? {
49+
func apply(toState state: inout WelcomeWorkflow.State, context: ApplyContext<WorkflowType>) -> WelcomeWorkflow.Output? {
5050
switch self {
5151
case .nameChanged(let updatedName):
5252
state.name = updatedName

Samples/SplitScreenContainer/DemoApp/DemoWorkflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension DemoWorkflow {
4343

4444
case viewTapped
4545

46-
func apply(toState state: inout DemoWorkflow.State) -> Never? {
46+
func apply(toState state: inout DemoWorkflow.State, context: ApplyContext<WorkflowType>) -> Never? {
4747
switch self {
4848
case .viewTapped:
4949
state += 1

Samples/TicTacToe/Sources/Authentication/AuthenticationWorkflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extension AuthenticationWorkflow {
6161
case authenticationError(AuthenticationService.AuthenticationError)
6262
case dismissAuthenticationAlert
6363

64-
func apply(toState state: inout AuthenticationWorkflow.State) -> AuthenticationWorkflow.Output? {
64+
func apply(toState state: inout AuthenticationWorkflow.State, context: ApplyContext<WorkflowType>) -> AuthenticationWorkflow.Output? {
6565
switch self {
6666
case .back:
6767
switch state {

Samples/TicTacToe/Sources/Authentication/LoginWorkflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension LoginWorkflow {
4949
case passwordUpdated(String)
5050
case login
5151

52-
func apply(toState state: inout LoginWorkflow.State) -> LoginWorkflow.Output? {
52+
func apply(toState state: inout LoginWorkflow.State, context: ApplyContext<WorkflowType>) -> LoginWorkflow.Output? {
5353
switch self {
5454
case .emailUpdated(let email):
5555
state.email = email

Samples/TicTacToe/Sources/Game/ConfirmQuitWorkflow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension ConfirmQuitWorkflow {
5656

5757
typealias WorkflowType = ConfirmQuitWorkflow
5858

59-
func apply(toState state: inout ConfirmQuitWorkflow.State) -> ConfirmQuitWorkflow.Output? {
59+
func apply(toState state: inout ConfirmQuitWorkflow.State, context: ApplyContext<WorkflowType>) -> ConfirmQuitWorkflow.Output? {
6060
switch self {
6161
case .cancel:
6262
return .cancel

0 commit comments

Comments
 (0)