Store
open class Store<State> : StoreType
This class is the default implementation of the StoreType
protocol. You will use this store in most
of your applications. You shouldn’t need to implement your own store.
You initialize the store with a reducer and an initial application state. If your app has multiple
reducers you can combine them by initializing a MainReducer
with all of your reducers as an
argument.
-
Declaration
Swift
private(set) public var state: State! { get set }
-
Declaration
Swift
public lazy var dispatchFunction: DispatchFunction! { get set }
-
Undocumented
Declaration
Swift
public var middleware: [Middleware<State>] { get set }
-
Initializes the store with a reducer, an initial state and a list of middleware.
Middleware is applied in the order in which it is passed into this constructor.
Declaration
Swift
public required init( reducer: @escaping Reducer<State>, state: State?, middleware: [Middleware<State>] = [], automaticallySkipsRepeats: Bool = true )
Parameters
reducer
Main reducer that processes incoming actions.
state
Initial state, if any. Can be
nil
and will be provided by the reducer in that case.middleware
Ordered list of action pre-processors, acting before the root reducer.
automaticallySkipsRepeats
If
true
, the store will attempt to skip idempotent state updates when a subscriber’s state type implementsEquatable
. Defaults totrue
. -
Declaration
Swift
open func subscribe<S: StoreSubscriber>(_ subscriber: S) where S.StoreSubscriberStateType == State
-
Declaration
Swift
open func subscribe<SelectedState, S: StoreSubscriber>( _ subscriber: S, transform: ((Subscription<State>) -> Subscription<SelectedState>)? ) where S.StoreSubscriberStateType == SelectedState
-
Declaration
Swift
open func unsubscribe(_ subscriber: AnyStoreSubscriber)
-
Undocumented
Declaration
Swift
open func _defaultDispatch(action: Action)
-
Declaration
Swift
open func dispatch(_ action: Action)
-
Declaration
Swift
open func dispatch(_ actionCreatorProvider: @escaping ActionCreator)
-
Declaration
Swift
open func dispatch(_ asyncActionCreatorProvider: @escaping AsyncActionCreator)
-
Declaration
Swift
open func dispatch(_ actionCreatorProvider: @escaping AsyncActionCreator, callback: DispatchCallback?)
-
Declaration
Swift
public typealias DispatchCallback = (State) -> Void
-
Declaration
Swift
public typealias ActionCreator = (_ state: State, _ store: Store) -> Action?
-
Declaration
Swift
public typealias AsyncActionCreator = ( _ state: State, _ store: Store, _ actionCreatorCallback: @escaping ((ActionCreator) -> Void) ) -> Void
-
Declaration
Swift
public func subscribe<SelectedState: Equatable, S: StoreSubscriber>( _ subscriber: S, transform: ((Subscription<State>) -> Subscription<SelectedState>)? ) where S.StoreSubscriberStateType == SelectedState
-
Undocumented
Declaration
Swift
public func subscribe<S: StoreSubscriber>(_ subscriber: S) where S.StoreSubscriberStateType == State