Skip to content

Commit f832f4d

Browse files
mbrandonwmluisbrown
authored andcommitted
Rename some generics in the store rescoping. (#1320)
(cherry picked from commit 2fe78298e3d1d6693d3c83054bb8487c84ec516a) # Conflicts: # Sources/ComposableArchitecture/Store.swift
1 parent bcac349 commit f832f4d

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

Sources/ComposableArchitecture/Effect.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public struct Effect<Output, Failure: Error> {
5656
extension Effect {
5757
/// An effect that does nothing and completes immediately. Useful for situations where you must
5858
/// return an effect, but you don't need to do anything.
59+
@inlinable
5960
public static var none: Self {
6061
Self(operation: .none)
6162
}

Sources/ComposableArchitecture/Store.swift

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -549,48 +549,44 @@ public final class Store<State, Action> {
549549
}
550550

551551
private protocol AnyScope {
552-
func rescope<State, Action, ChildState, ChildAction>(
553-
_ store: Store<State, Action>,
554-
state toNewChildState: @escaping (State) -> ChildState,
555-
action fromNewChildAction: @escaping (ChildAction) -> Action
556-
) -> Store<ChildState, ChildAction>
552+
func rescope<ScopedState, ScopedAction, RescopedState, RescopedAction>(
553+
_ store: Store<ScopedState, ScopedAction>,
554+
state toRescopedState: @escaping (ScopedState) -> RescopedState,
555+
action fromRescopedAction: @escaping (RescopedAction) -> ScopedAction
556+
) -> Store<RescopedState, RescopedAction>
557557
}
558558

559559
private struct Scope<RootState, RootAction>: AnyScope {
560560
let root: Store<RootState, RootAction>
561-
let toChildState: Any
562-
let fromChildAction: Any
561+
let fromScopedAction: Any
563562

564563
init(root: Store<RootState, RootAction>) {
565-
self.init(root: root, toChildState: { $0 }, fromChildAction: { $0 })
564+
self.init(root: root, fromScopedAction: { $0 })
566565
}
567566

568-
private init<State, Action>(
567+
private init<ScopedAction>(
569568
root: Store<RootState, RootAction>,
570-
toChildState: @escaping (RootState) -> State,
571-
fromChildAction: @escaping (Action) -> RootAction
569+
fromScopedAction: @escaping (ScopedAction) -> RootAction
572570
) {
573571
self.root = root
574-
self.toChildState = toChildState
575-
self.fromChildAction = fromChildAction
572+
self.fromScopedAction = fromScopedAction
576573
}
577574

578-
func rescope<State, Action, ChildState, ChildAction>(
579-
_ store: Store<State, Action>,
580-
state toChildState: @escaping (State) -> ChildState,
581-
action fromChildAction: @escaping (ChildAction) -> Action
582-
) -> Store<ChildState, ChildAction> {
583-
let toState = self.toChildState as! (RootState) -> State
584-
let fromAction = self.fromChildAction as! (Action) -> RootAction
585-
575+
func rescope<ScopedState, ScopedAction, RescopedState, RescopedAction>(
576+
_ scopedStore: Store<ScopedState, ScopedAction>,
577+
state toRescopedState: @escaping (ScopedState) -> RescopedState,
578+
action fromRescopedAction: @escaping (RescopedAction) -> ScopedAction
579+
) -> Store<RescopedState, RescopedAction> {
580+
let fromScopedAction = self.fromScopedAction as! (ScopedAction) -> RootAction
581+
586582
var isSending = false
587-
let childStore = Store<ChildState, ChildAction>(
588-
initialState: toChildState(store.state),
589-
reducer: .init { childState, childAction, _ in
583+
let rescopedStore = Store<RescopedState, RescopedAction>(
584+
initialState: toRescopedState(scopedStore.state),
585+
reducer: .init { rescopedState, rescopedAction, _ in
590586
isSending = true
591587
defer { isSending = false }
592-
let task = self.root.send(fromAction(fromChildAction(childAction)))
593-
childState = toChildState(store.state)
588+
let task = self.root.send(fromScopedAction(fromRescopedAction(rescopedAction)))
589+
rescopedState = toRescopedState(scopedStore.state)
594590
if let task = task {
595591
return .fireAndForget { await task.cancellableValue }
596592
} else {
@@ -599,17 +595,16 @@ private struct Scope<RootState, RootAction>: AnyScope {
599595
},
600596
environment: ()
601597
)
602-
childStore.parentDisposable = store.producer
598+
scopedStore.parentDisposable = scopedStore.producer
603599
.skip(first: 1)
604-
.startWithValues { [weak childStore] newValue in
600+
.startWithValues { [weak rescopedStore] newValue in
605601
guard !isSending else { return }
606-
childStore?.state = toChildState(newValue)
602+
rescopedStore?.state = toRescopedState(newValue)
607603
}
608-
childStore.scope = Scope<RootState, RootAction>(
604+
rescopedStore.scope = Scope<RootState, RootAction>(
609605
root: self.root,
610-
toChildState: { toChildState(toState($0)) },
611-
fromChildAction: { fromAction(fromChildAction($0)) }
606+
fromScopedAction: { fromScopedAction(fromRescopedAction($0)) }
612607
)
613-
return childStore
608+
return rescopedStore
614609
}
615610
}

0 commit comments

Comments
 (0)