0001 /** 0002 A protocol that defines storage of an observable state and dispatch methods to 0003 modify it. Typically you will implement this on a struct and create a shared 0004 instance that you reference throughout your application to get the state or 0005 dispatch actions to change it. 0006 0007 Sample store: 0008 0009 ```swift 0010 struct AppState { 0011 var id = ObservableProperty(0) 0012 } 0013 0014 struct Store: StoreType { 0015 var state: ObservableProperty<AppState> 0016 } 0017 0018 let initialState = AppState() 0019 var store = Store(state: ObservableProperty(initialState)) 0020 ``` 0021 */ 0022 public protocol StoreType{ 0023 /** 0024 An observable state of the store. This is accessed directly to subscribe to 0025 changes. 0026 */ 0027 typealias ObservableState
Store.swift:48 public extension StoreType {: ObservablePropertyType 0028 0029 /** 0030 The type of the root state of the application. 0031 0032 - note: This is inferred from the `reduce` method implementation. 0033 */ 0034 var state
Store.swift:34 var state: ObservableState { get set }Store.swift:39 mutating func dispatch<Action: ActionType where Action.StateValueType == ObservableState.ValueType>(action: Action)Store.swift:53 public mutating func dispatch<Action: ActionType where Action.StateValueType == ObservableState.ValueType>(action: Action) {: ObservableState { get set } 0035 0036 /** 0037 Dispatch an action that will mutate the state of the store. 0038 */ 0039 mutating func dispatch<Action: ActionType where Action.StateValueType == ObservableState.ValueType>(action: Action) 0040 0041 /** 0042 Dispatch an async action that when called should trigger another dispatch 0043 with a synchronous action. 0044 */ 0045 func dispatch<DynamicAction: DynamicActionType>(action: DynamicAction) -> DynamicAction.ResponseType 0046 } 0047 0048 public extension StoreType { 0049 /** 0050 Dispatches an action by settings the state's value to the result of 0051 calling it's `reduce` method. 0052 */ 0053 public mutating func dispatch<Action: ActionType where Action.StateValueType == ObservableState.ValueType>(action: Action) { 0054 state.value = action.reduce(state.value) 0055 } 0056 0057 /** 0058 Dispatches an async action by calling it's `call` method. 0059 */ 0060 public func dispatch<DynamicAction: DynamicActionType>(action: DynamicAction) -> DynamicAction.ResponseType { 0061 return action.call() 0062 } 0063 } 0064
Store.swift:54 state.value = action.reduce(state.value)Store.swift:54 state.value = action.reduce(state.value)