Files
swift-composable-architectu…/Sources/swift-composable-architecture-benchmark/StoreScope.swift
Stephen Celis 1f2a904872 Fix package build in 5.7 (#2675)
The internal benchmarks package was no longer building in 5.7.
2023-12-21 13:01:47 -08:00

38 lines
889 B
Swift

import Benchmark
import ComposableArchitecture
#if swift(>=5.9)
@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
}
}
}
}
#endif
let storeScopeSuite = BenchmarkSuite(name: "Store scoping") { suite in
#if swift(>=5.9)
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)
}
#endif
}