Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import Combine
  2. import SwiftUI
  3.  
  4. // 1
  5. class Store: BindableObject {
  6.  
  7. // 2
  8. public let didChange = PassthroughSubject<Store, Never>()
  9.  
  10. private var currentState: [TodoItem]
  11. private var reducer: TodoReducer
  12.  
  13. // 3
  14. var state: [TodoItem] { currentState }
  15.  
  16. // 4
  17. init(initialState: [TodoItem]) {
  18. self.currentState = initialState
  19. self.reducer = TodoReducer()
  20. }
  21.  
  22. // 5
  23. func dispatch(action: TodoAction) {
  24. let newState = reducer.reduce(oldState: currentState, action: action)
  25. currentState = newState
  26.  
  27. // 6
  28. didChange.send(self)
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement