mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-20 09:11:33 +01:00
* Add `Store.init` that takes reducer builder * wip * wip * added some tests * wip * wip * wip --------- Co-authored-by: Brandon Williams <mbrandonw@hey.com>
31 lines
724 B
Swift
31 lines
724 B
Swift
import Benchmark
|
|
import ComposableArchitecture
|
|
|
|
private struct Counter: ReducerProtocol {
|
|
typealias State = Int
|
|
typealias Action = Bool
|
|
func reduce(into state: inout Int, action: Bool) -> EffectTask<Bool> {
|
|
if action {
|
|
state += 1
|
|
return .none
|
|
} else {
|
|
state -= 1
|
|
return .none
|
|
}
|
|
}
|
|
}
|
|
|
|
let storeScopeSuite = BenchmarkSuite(name: "Store scoping") { suite in
|
|
var store = Store(initialState: 0) { Counter() }
|
|
var viewStores: [ViewStore<Int, Bool>] = [ViewStore(store)]
|
|
for _ in 1...4 {
|
|
store = store.scope(state: { $0 })
|
|
viewStores.append(ViewStore(store))
|
|
}
|
|
let lastViewStore = viewStores.last!
|
|
|
|
suite.benchmark("Nested store") {
|
|
lastViewStore.send(true)
|
|
}
|
|
}
|