Protocols
The following protocols are available globally.
-
This protocol is used when you want to do some async behavior that updates the store. It is very minimal in that it’s not allowed to modify the store directly. The async behavior is done within the
call
method and to make changes it should dispatch a synchronous action.Sample Action:
See morestruct FetchUsers: DynamicActionType { func call() { someApi.fetchUsers { users in store.dispatch(SetUsersAction(users: users)) } } } store.dispatch(UpdateIdAction(id: 1))
Declaration
Swift
public protocol DynamicActionType
-
A protocol that defines storage of an observable state and dispatch methods to modify it. Typically you will implement this on a struct and create a shared instance that you reference throughout your application to get the state or dispatch actions to change it.
Sample store:
See morestruct AppState { var id = ObservableProperty(0) } struct Store: StoreType { var state: ObservableProperty<AppState> } let initialState = AppState() var store = Store(state: ObservableProperty(initialState))
Declaration
Swift
public protocol StoreType
-
This protocol is used when you want to make modifications to the store’s state. All changes to the store go through this type.
Sample Action:
See morestruct UpdateIdAction: ActionType { let id: Int func reduce(state: AppState) -> AppState { state.id.value = id return state } } store.dispatch(UpdateIdAction(id: 1))
Declaration
Swift
public protocol ActionType
-
This is the protocol that the state the store holds must implement.
To use a custom state type, this protocol must be implemented on that object.
This is useful if you want to plug in a reactive programming library and use that for state instead of the built-in ObservableProperty type.
See moreDeclaration
Swift
public protocol ObservablePropertyType