-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeatureA.swift
66 lines (53 loc) · 1.67 KB
/
FeatureA.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import SwiftUI
import ComposableArchitecture
import TCAExtensions
/*
Simple example of `StackReducer` implementation that appends destinations on the stack.
*/
public struct FeatureA: Reducer {
@Reducer
public enum Path {
case screenOne(ScreenOneReducer)
case screenTwo(ScreenTwoReducer)
}
public init() {}
public var body: some StackReducerOf<Path> {
Reduce { state, action in
switch action {
case let .element(id: _, action: .internal(internalAction)):
switch internalAction {
case let .screenOne(.delegate(delegate)):
switch delegate {
case let .goToScreenTwo(number):
state.append(.screenTwo(.init(number: number)))
}
return .none
case .screenTwo:
return .none
case .screenOne:
return .none
}
case .element:
return .none
case .popFrom:
return .none
case .push:
return .none
}
}
}
}
public struct FeatureAView: View {
public init(store: StoreOf<FeatureA.Path>) {
self.store = store
}
@Bindable var store: StoreOf<FeatureA.Path>
public var body: some View {
switch store.case {
case .screenOne(let store):
ScreenOne(store: store)
case .screenTwo(let store):
ScreenTwo(store: store)
}
}
}