Files
swift-composable-architectu…/Sources/swift-composable-architecture-benchmark/StoreScope.swift
Stephen Celis 767231d179 Add Store.init that takes reducer builder (#2087)
* Add `Store.init` that takes reducer builder

* wip

* wip

* added some tests

* wip

* wip

* wip

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2023-05-11 12:30:08 -07:00

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)
}
}