Store
Undocumented
-
The current state stored in the store
Declaration
Swift
var appState: StateType { get }
-
Subscribes the provided subscriber to this store. Subscribers will receive a call to
newState
whenever the state in this store changes.Declaration
Swift
func subscribe(subscriber: AnyStoreSubscriber)
Parameters
subscriber
Subscriber that will receive store updates
-
Unsubscribes the provided subscriber. The subscriber will no longer receive state updates from this store.
Declaration
Swift
func unsubscribe(subscriber: AnyStoreSubscriber)
Parameters
subscriber
Subscriber that will be unsubscribed
-
Dispatches an action. This is the simplest way to modify the stores state.
Example of dispatching an action:
swift store.dispatch( CounterAction.IncreaseCounter )
- parameter action: The action that is being dispatched to the storeDeclaration
Swift
func dispatch(action: ActionType)
Parameters
action
The action that is being dispatched to the store
-
Dispatches an action creator to the store. Action creators are functions that generate actions. They are called by the store and receive the current state of the application and a reference to the store as their input.
Based on that input the action creator can either return an action or not. Alternatively the action creator can also perform an asynchronous operation and dispatch a new action at the end of it.
Example of an action creator:
swift func deleteNote(noteID: Int) -> ActionCreator { return { state, store in // only delete note if editing is enabled if (state.editingEnabled == true) { return NoteDataAction.DeleteNote(noteID) } else { return nil } } }
This action creator can then be dispatched as following:
swift store.dispatch( noteActionCreatore.deleteNote(3) )
Declaration
Swift
func dispatch(actionCreatorProvider: ActionCreator)
-
Dispatches an async action creator to the store. An async action creator generates an action creator asynchronously. Use this method if you want to wait for the state change triggered by the asynchronously generated action creator.
Declaration
Swift
func dispatch(asyncActionCreatorProvider: AsyncActionCreator)
-
Dispatches an action and calls the callback as soon as the action has been processed. You will receive the updated store state as part of this callback.
Example of dispatching an action and implementing a callback:
swift store.dispatch( CounterAction.IncreaseCounter ) { state in print("New state: \(state)") }
- parameter action: The action that is being dispatched to the storeDeclaration
Swift
func dispatch(action: ActionType, callback: DispatchCallback?)
Parameters
action
The action that is being dispatched to the store
-
Undocumented
-
Undocumented