Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Combine
- import SwiftUI
- // 1
- class Store: BindableObject {
- // 2
- public let didChange = PassthroughSubject<Store, Never>()
- private var currentState: [TodoItem]
- private var reducer: TodoReducer
- // 3
- var state: [TodoItem] { currentState }
- // 4
- init(initialState: [TodoItem]) {
- self.currentState = initialState
- self.reducer = TodoReducer()
- }
- // 5
- func dispatch(action: TodoAction) {
- let newState = reducer.reduce(oldState: currentState, action: action)
- currentState = newState
- // 6
- didChange.send(self)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement