Types
ReduxSubscription = proc (): void
ReduxUnsubscription = proc (): void
ReduxAction = ref object of RootObj
ReduxReducer[T] = proc (state: T; action: ReduxAction): T
ReduxStore[T] = ref object state: T reducer: ReduxReducer[T] subscriptions: seq[ReduxSubscription] middlewares: seq[proc (action: ReduxAction): ReduxAction]
ReduxMiddleware[T] = proc (store: ReduxStore[T]): proc ( next: proc (store: ReduxStore[T]; action: ReduxAction): void): proc ( action: ReduxAction): ReduxAction
Procs
proc newReduxStore[T](reducer: ReduxReducer[T]): ReduxStore[T]
- Creates a new redux store of a given type
proc newReduxStore[T](reducer: ReduxReducer[T]; initialState: T): ReduxStore[T]
- Creates a new redux store of a given type
proc newReduxStore[T](reducer: ReduxReducer[T]; initialState: T; middlewares: seq[ReduxMiddleware[T]]): ReduxStore[T]
- Creates a new redux store of a given type
proc getState[T](store: ReduxStore[T]): T
- Returns the state of the store
proc subscribe[T](store: ReduxStore[T]; fn: ReduxSubscription): ReduxUnsubscription
- Subscribe to changes on the store, to be notified of It returns an unsubscription closure to unsubscribe to the store
proc unsubscribe[T](store: ReduxStore[T]; id: int): void
- Unsubscribes from the store
proc dispatch[T](store: ReduxStore[T]; action: ReduxAction): ReduxAction
- Dispatches an action to the reducer, so that the reducer produces the new state