Skip to content

Commit ad76a40

Browse files
authored
Merge pull request #37 from Ryu0118/rename-scope-state-to-view-state
Rename ScopeState to ViewState
2 parents 3f537e5 + 731d9c2 commit ad76a40

23 files changed

+145
-145
lines changed

.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct MyReducer: ReducerProtocol {
5353
}
5454
}
5555

56-
@ScopeState
56+
@ViewState
5757
struct MyView: View {
5858
@State var counter = 0
5959

@@ -105,7 +105,7 @@ struct MyReducer: ReducerProtocol {
105105
}
106106
}
107107

108-
@ScopeState
108+
@ViewState
109109
struct MyView: View {
110110
@State var counter = 0
111111

@@ -168,7 +168,7 @@ struct MyReducer: ReducerProtocol {
168168
}
169169
}
170170

171-
@ScopeState
171+
@ViewState
172172
struct MyView: View {
173173
@State var email: String = ""
174174
@State var password: String = ""
@@ -196,7 +196,7 @@ If you want to send the Action of the child Reducer to the parent Reducer, use p
196196
This is the sample code.
197197

198198
```Swift
199-
@ScopeState
199+
@ViewState
200200
struct ParentView: View {
201201
let store: Store<ParentReducer> = Store(reducer: ParentReducer())
202202

@@ -220,7 +220,7 @@ struct ParentReducer: ReducerProtocol {
220220
}
221221
}
222222

223-
@ScopeState
223+
@ViewState
224224
struct ChildView: View, ActionSendable {
225225
let store: Store<ChildReducer> = Store(reducer: ChildReducer())
226226

@@ -248,12 +248,12 @@ struct ChildReducer: ReducerProtocol {
248248
### Testing
249249
You can write a test like this.
250250
```Swift
251-
let testStore = TestView().testStore(states: .init())
251+
let testStore = TestView().testStore(viewState: .init())
252252
await testStore.send(.increment) {
253253
$0.count = 1
254254
}
255255

256-
let testStore = TestView().testStore(states: .init())
256+
let testStore = TestView().testStore(viewState: .init())
257257
await testStore.send(.send)
258258
await testStore.receive(.increment) {
259259
$0.count = 1

Sources/SimplexArchitecture/ActionSendable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44
/// A protocol for send actions to a store.
55
public protocol ActionSendable<Reducer> {
66
associatedtype Reducer: ReducerProtocol<Self>
7-
associatedtype States: StatesProtocol
7+
associatedtype ViewState: ViewStateProtocol
88

99
/// The store to which actions will be sent.
1010
var store: Store<Reducer> { get }

Sources/SimplexArchitecture/Internal/ActionTransition.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Foundation
22

3-
/// ``ActionTransition`` represents a transition between states in a reducer. It captures the previous and next states, the associated side effect,effect context, and the action triggering the transition.
3+
/// ``ActionTransition`` represents a transition between viewState in a reducer. It captures the previous and next viewState, the associated side effect,effect context, and the action triggering the transition.
44
struct ActionTransition<Reducer: ReducerProtocol> {
55
/// Represents a state. It includes the target state and the reducer state.
66
struct State {
7-
let state: Reducer.Target.States?
7+
let state: Reducer.Target.ViewState?
88
let reducerState: Reducer.ReducerState?
99
}
1010

@@ -61,7 +61,7 @@ struct ActionTransition<Reducer: ReducerProtocol> {
6161
) -> StateContainer<Reducer.Target> {
6262
.init(
6363
target,
64-
states: state.state,
64+
viewState: state.state,
6565
reducerState: state.reducerState
6666
)
6767
}

Sources/SimplexArchitecture/Macros.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/// Macro to create States structure by extracting properties to which property wrappers such as @State, @Binding @Published, etc. are applied.
1+
/// Macro to create ViewState structure by extracting properties to which property wrappers such as @State, @Binding @Published, etc. are applied.
22
///
3-
/// It is conformed to the `ActionSendable` protocol by the `ScopeState` macro.
3+
/// It is conformed to the `ActionSendable` protocol by the `ViewState` macro.
44
///
55
/// Here is a example code.
66
/// ```
7-
/// @ScopeState
7+
/// @ViewState
88
/// struct MyView: View {
99
/// let store: Store<MyReducer>
1010
///
@@ -40,7 +40,7 @@
4040
/// ```
4141
/// Here is a sample code if you want to use ReducerState.
4242
/// ```
43-
/// @ScopeState
43+
/// @ViewState
4444
/// struct MyView: View {
4545
/// let store: Store<MyReducer>
4646
///
@@ -74,7 +74,7 @@
7474
/// }
7575
/// }
7676
/// ```
77-
@attached(member, names: named(States))
77+
@attached(member, names: named(ViewState))
7878
@attached(extension, conformances: ActionSendable)
79-
public macro ScopeState() =
80-
#externalMacro(module: "SimplexArchitectureMacrosPlugin", type: "ScopeState")
79+
public macro ViewState() =
80+
#externalMacro(module: "SimplexArchitectureMacrosPlugin", type: "ViewStateMacro")

Sources/SimplexArchitecture/Reducer/Pullbackable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Foundation
55
///
66
/// Here is a sample code.
77
/// ```
8-
/// @ScopeState
8+
/// @ViewState
99
/// struct ParentView: View {
1010
/// let store: Store<ParentReducer> = Store(reducer: ParentReducer())
1111
///
@@ -29,7 +29,7 @@ import Foundation
2929
/// }
3030
/// }
3131
///
32-
/// @ScopeState
32+
/// @ViewState
3333
/// struct ChildView: View, ActionSendable {
3434
/// let store: Store<ChildReducer> = Store(reducer: ChildReducer())
3535
///

Sources/SimplexArchitecture/Reducer/ReducerProtocol.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/// }
2020
/// }
2121
///
22-
/// @ScopeState
22+
/// @ViewState
2323
/// struct MyView: View {
2424
/// @State var counter = 0
2525
/// let store = Store(reducer: MyReducer())
@@ -64,7 +64,7 @@
6464
/// }
6565
/// }
6666
///
67-
/// @ScopeState
67+
/// @ViewState
6868
/// struct MyView: View {
6969
/// @State var counter = 0
7070
///
@@ -89,7 +89,7 @@
8989
/// ```
9090
///
9191
public protocol ReducerProtocol<Target> {
92-
/// Target for the Reducer to change state, which must conform to ActionSendable and is automatically conformed to by the StoreBuilder or ScopeState macros
92+
/// Target for the Reducer to change state, which must conform to ActionSendable and is automatically conformed to by the StoreBuilder or ViewState macros
9393
associatedtype Target: ActionSendable<Self>
9494
/// State used by Reducer. Since the View is not update when the value of ReducerState is changed, it is used for the purpose of improving performance, etc.
9595
/// The default is Never.

Sources/SimplexArchitecture/StateContainer.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,36 @@ public final class StateContainer<Target: ActionSendable> {
1111

1212
var _reducerState: Target.Reducer.ReducerState?
1313
var entity: Target
14-
@TestOnly var states: Target.States?
14+
@TestOnly var viewState: Target.ViewState?
1515

1616
init(
1717
_ entity: consuming Target,
18-
states: Target.States? = nil,
18+
viewState: Target.ViewState? = nil,
1919
reducerState: consuming Target.Reducer.ReducerState? = nil
2020
) {
2121
self.entity = entity
22-
self.states = states
22+
self.viewState = viewState
2323
self._reducerState = reducerState
2424
}
2525

26-
public subscript<U>(dynamicMember keyPath: WritableKeyPath<Target.States, U>) -> U {
26+
public subscript<U>(dynamicMember keyPath: WritableKeyPath<Target.ViewState, U>) -> U {
2727
_read {
2828
guard !_XCTIsTesting else {
29-
yield states![keyPath: keyPath]
29+
yield viewState![keyPath: keyPath]
3030
return
3131
}
32-
if let viewKeyPath = Target.States.keyPathMap[keyPath] as? WritableKeyPath<Target, U> {
32+
if let viewKeyPath = Target.ViewState.keyPathMap[keyPath] as? WritableKeyPath<Target, U> {
3333
yield entity[keyPath: viewKeyPath]
3434
} else {
3535
fatalError()
3636
}
3737
}
3838
_modify {
3939
guard !_XCTIsTesting else {
40-
yield &states![keyPath: keyPath]
40+
yield &viewState![keyPath: keyPath]
4141
return
4242
}
43-
if let viewKeyPath = Target.States.keyPathMap[keyPath] as? WritableKeyPath<Target, U> {
43+
if let viewKeyPath = Target.ViewState.keyPathMap[keyPath] as? WritableKeyPath<Target, U> {
4444
yield &entity[keyPath: viewKeyPath]
4545
} else {
4646
fatalError()
@@ -49,6 +49,6 @@ public final class StateContainer<Target: ActionSendable> {
4949
}
5050

5151
func copy() -> Self {
52-
Self(entity, states: states, reducerState: _reducerState)
52+
Self(entity, viewState: viewState, reducerState: _reducerState)
5353
}
5454
}

Sources/SimplexArchitecture/Store/Store+send.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ extension Store {
7676
sideEffect = reduce(container, action)
7777
sentFromEffectActions.append(
7878
ActionTransition(
79-
previous: .init(state: before.states, reducerState: before._reducerState),
80-
next: .init(state: container.states, reducerState: before._reducerState),
79+
previous: .init(state: before.viewState, reducerState: before._reducerState),
80+
next: .init(state: container.viewState, reducerState: before._reducerState),
8181
effect: sideEffect,
8282
effectContext: effectContext,
8383
for: action

Sources/SimplexArchitecture/Store/Store.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,25 @@ public final class Store<Reducer: ReducerProtocol> {
5353

5454
public func getContainer(
5555
for target: Reducer.Target,
56-
states: Reducer.Target.States? = nil
56+
viewState: Reducer.Target.ViewState? = nil
5757
) -> StateContainer<Reducer.Target> {
5858
if let container {
5959
container
6060
} else {
61-
StateContainer(target, states: states, reducerState: initialReducerState?())
61+
StateContainer(target, viewState: viewState, reducerState: initialReducerState?())
6262
}
6363
}
6464

6565
@inlinable
6666
@discardableResult
6767
public func setContainerIfNeeded(
6868
for target: Reducer.Target,
69-
states: Reducer.Target.States? = nil
69+
viewState: Reducer.Target.ViewState? = nil
7070
) -> StateContainer<Reducer.Target> {
7171
if let container {
7272
return container
7373
} else {
74-
let container = getContainer(for: target, states: states)
74+
let container = getContainer(for: target, viewState: viewState)
7575
self.container = container
7676
return container
7777
}

0 commit comments

Comments
 (0)