Files
swift-composable-architectu…/Sources/swift-composable-architecture-benchmark/StoreScope.swift
Brandon Williams 3a02c5e9fe Fix a bunch of DocC references. (#3287)
* Fix a bunch of DocC references.

* wip

* doc fix

* issue message fix

* swift-navigation 2.0.5
2024-08-15 13:02:49 -04:00

35 lines
811 B
Swift

import Benchmark
import ComposableArchitecture
@Reducer
private struct Counter {
typealias State = Int
typealias Action = Bool
var body: some Reducer<State, Action> {
Reduce { state, action in
if action {
state += 1
return .none
} else {
state -= 1
return .none
}
}
}
}
@available(*, deprecated)
let storeScopeSuite = BenchmarkSuite(name: "Store scoping") { suite in
var store = Store(initialState: 0) { Counter() }
var viewStores: [ViewStore<Int, Bool>] = [ViewStore(store, observe: { $0 })]
for _ in 1...4 {
store = store.scope(state: { $0 }, action: { $0 })
viewStores.append(ViewStore(store, observe: { $0 }))
}
let lastViewStore = viewStores.last!
suite.benchmark("Nested store") {
lastViewStore.send(true)
}
}