Child store caching improvements (#2627)

* Use `ScopeID` for all cached child stores

* wip

* wip

* wip

* wip

* wip

* wip
This commit is contained in:
Stephen Celis
2023-12-07 12:39:37 -08:00
committed by GitHub
parent 41f79c0c65
commit c2a27dcaad
9 changed files with 147 additions and 123 deletions

View File

@@ -29,15 +29,11 @@ public struct NavigationStackStore<State, Action, Root: View, Destination: View>
) {
self.root = root()
self.destination = { component in
var state = component.element
return destination(
destination(
store
.scope(
state: {
state = $0[id: component.id] ?? state
return state
},
id: { _ in component.id },
state: { $0[id: component.id]! },
id: store.id(state: \.[id: component.id]!, action: \.[id: component.id]),
action: { .element(id: component.id, action: $0) },
isInvalid: { !$0.ids.contains(component.id) },
removeDuplicates: nil
@@ -69,15 +65,11 @@ public struct NavigationStackStore<State, Action, Root: View, Destination: View>
) where Destination == SwitchStore<State, Action, D> {
self.root = root()
self.destination = { component in
var state = component.element
return SwitchStore(
SwitchStore(
store
.scope(
state: {
state = $0[id: component.id] ?? state
return state
},
id: { _ in component.id },
state: { $0[id: component.id]! },
id: store.id(state: \.[id: component.id]!, action: \.[id: component.id]),
action: { .element(id: component.id, action: $0) },
isInvalid: { !$0.ids.contains(component.id) },
removeDuplicates: nil