Module redux_nim

Types

ReduxSubscription = proc (): void
The type of a redux subscription
ReduxUnsubscription = proc (): void
The type of a redux subscription
ReduxAction = ref object of RootObj
The type of a redux action
ReduxReducer[T] = proc (state: T; action: ReduxAction): T
The type of a redux reducer
ReduxStore[T] = ref object
  state: T
  reducer: ReduxReducer[T]
  subscriptions: seq[ReduxSubscription]
  middlewares: seq[proc (action: ReduxAction): ReduxAction]
  isDispatching: bool
The type of a redux store
ReduxMiddleware[T] = proc (store: ReduxStore[T]): proc (
    next: proc (store: ReduxStore[T]; action: ReduxAction): ReduxAction): proc (
    action: ReduxAction): ReduxAction
The type of a redux middleware
ReduxInDispatchingProcessError = object of Exception
The type of a redux dispatch in progress error
ReduxDispatchProcessError = object of Exception
The type of a redux dispatch error

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 {...}{.raises: [ReduxInDispatchingProcessError].}
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 {...}{.
    raises: [ReduxInDispatchingProcessError, ReduxDispatchProcessError].}
Dispatches an action to the reducer, so that the reducer produces the new state