API - Index
Redux-Data-Model API Reference Guide
This reference guide lists all methods exposed by redux-data-model. Contributions like linguistic improvements, adding more details to the descriptions or additional examples are highly appreciated! Please note that the docs are generated from source.
redux-data-model
Index
Error Classes
- ActionDataIsntPlainObjectError
- BlockingEffectWithoutMatchingEffectError
- DuplicatedActionTypesError
- DuplicatedModelNamespaceError
- EmptyNamespaceError
- InvalidNamespaceError
- KeyConflictInMergePropsError
- ModelNotReduxInitializedError
- ModelNotSagaInitializedError
- NamespaceIsntAStringError
- NonCompatibleActionError
- UndefinedBlockingSagaEffectError
- UndefinedReducerOrEffectError
- UndefinedSagaEffectError
- UndefinedSelectorError
Other Classes
Interfaces
Type aliases
- ActionCreatorsMapObject
- ActionType
- ActionTypesMapObject
- BlockingEffectFunction
- BlockingEffectMap
- BlockingSagaEffects
- BoundNamespacedActionCreatorsMapObject
- EffectFunction
- EffectMap
- EffectModelFunction
- EffectModelMap
- MapDispatchToPropsWithActionCreators
- MapDispatchToPropsWithActionCreatorsFunction
- MapStateToPropsWithSelectors
- NamespacedActionCreatorsMapObject
- NamespacedDispatchersMapObject
- NamespacedSelectorsMapObject
- ReducerFunction
- ReducerMap
- SagaEffects
- SelectorFunction
- SelectorMap
- SelectorModelFunction
- SelectorModelMap
High Order Component (HOC) Functions
React Hook Functions
Redux/Saga Setup Functions
Type aliases
ActionCreatorsMapObject
Ƭ ActionCreatorsMapObject: object
Defined in packages/redux-data-model/src/baseTypes.ts:24
Type declaration:
ActionType
Ƭ ActionType: string
Defined in packages/redux-data-model/src/baseTypes.ts:4
ActionTypesMapObject
Ƭ ActionTypesMapObject: object
Defined in packages/redux-data-model/src/baseTypes.ts:16
Type declaration:
BlockingEffectFunction
Ƭ BlockingEffectFunction: function
Defined in packages/redux-data-model/src/baseTypes.ts:42
Type declaration:
▸ (actionType
: ActionType, blockingSagaEffects
: Effects, modelEffects
: ModelEffect): any
Parameters:
Name | Type |
---|---|
actionType | ActionType |
blockingSagaEffects | Effects |
modelEffects | ModelEffect |
BlockingEffectMap
Ƭ BlockingEffectMap: object
Defined in packages/redux-data-model/src/baseTypes.ts:57
Type declaration:
BlockingSagaEffects
Ƭ BlockingSagaEffects: typeof blockingSagaEffects
Defined in packages/redux-data-model/src/model.ts:70
BoundNamespacedActionCreatorsMapObject
Ƭ BoundNamespacedActionCreatorsMapObject: object
Defined in packages/redux-data-model/src/baseTypes.ts:81
Type declaration:
EffectFunction
Ƭ EffectFunction: function
Defined in packages/redux-data-model/src/baseTypes.ts:37
Type declaration:
▸ (actionData
: PayloadAction, sagaEffects
: Effects, actionCreators
: ActionCreatorsMapObject‹ReducerPayloads›): any
Parameters:
Name | Type |
---|---|
actionData | PayloadAction |
sagaEffects | Effects |
actionCreators | ActionCreatorsMapObject‹ReducerPayloads› |
EffectMap
Ƭ EffectMap: object
Defined in packages/redux-data-model/src/baseTypes.ts:54
Type declaration:
EffectModelFunction
Ƭ EffectModelFunction: function
Defined in packages/redux-data-model/src/baseTypes.ts:66
Type declaration:
▸ (actionData?
: any): any
Parameters:
Name | Type |
---|---|
actionData? | any |
EffectModelMap
Ƭ EffectModelMap: Record‹string, Saga›
Defined in packages/redux-data-model/src/baseTypes.ts:71
MapDispatchToPropsWithActionCreators
Ƭ MapDispatchToPropsWithActionCreators: MapDispatchToPropsWithActionCreatorsFunction‹TDispatchProps, TOwnProps› | TDispatchProps
Defined in packages/redux-data-model/src/baseTypes.ts:91
MapDispatchToPropsWithActionCreatorsFunction
Ƭ MapDispatchToPropsWithActionCreatorsFunction: function
Defined in packages/redux-data-model/src/baseTypes.ts:85
Type declaration:
▸ (dispatch
: Dispatch‹AnyAction›, ownProps
: TOwnProps, dispatchers
: NamespacedDispatchersMapObject): TDispatchProps
Parameters:
Name | Type |
---|---|
dispatch | Dispatch‹AnyAction› |
ownProps | TOwnProps |
dispatchers | NamespacedDispatchersMapObject |
MapStateToPropsWithSelectors
Ƭ MapStateToPropsWithSelectors: function
Defined in packages/redux-data-model/src/baseTypes.ts:94
Type declaration:
▸ (state
: State, ownProps
: TOwnProps, modelSelectors
: NamespacedSelectorsMapObject): TStateProps
Parameters:
Name | Type |
---|---|
state | State |
ownProps | TOwnProps |
modelSelectors | NamespacedSelectorsMapObject |
NamespacedActionCreatorsMapObject
Ƭ NamespacedActionCreatorsMapObject: Record‹string, any›
Defined in packages/redux-data-model/src/baseTypes.ts:74
NamespacedDispatchersMapObject
Ƭ NamespacedDispatchersMapObject: Record‹string, any›
Defined in packages/redux-data-model/src/baseTypes.ts:75
NamespacedSelectorsMapObject
Ƭ NamespacedSelectorsMapObject: Record‹string, any›
Defined in packages/redux-data-model/src/baseTypes.ts:77
ReducerFunction
Ƭ ReducerFunction: function
Defined in packages/redux-data-model/src/baseTypes.ts:34
Type declaration:
▸ (state
: State, payload
: PayloadAction, action
: ActionWithPayload‹PayloadAction›): void
Parameters:
Name | Type |
---|---|
state | State |
payload | PayloadAction |
action | ActionWithPayload‹PayloadAction› |
ReducerMap
Ƭ ReducerMap: object
Defined in packages/redux-data-model/src/baseTypes.ts:51
Type declaration:
SagaEffects
Ƭ SagaEffects: typeof sagaEffects
Defined in packages/redux-data-model/src/model.ts:69
SelectorFunction
Ƭ SelectorFunction: function
Defined in packages/redux-data-model/src/baseTypes.ts:33
Type declaration:
▸ (state
: State, props
: Props, allState
: any): any
Parameters:
Name | Type |
---|---|
state | State |
props | Props |
allState | any |
SelectorMap
Ƭ SelectorMap: object
Defined in packages/redux-data-model/src/baseTypes.ts:46
Type declaration:
SelectorModelFunction
Ƭ SelectorModelFunction: function
Defined in packages/redux-data-model/src/baseTypes.ts:63
Type declaration:
▸ (state
: State, props?
: SelectorPayload): any
Parameters:
Name | Type |
---|---|
state | State |
props? | SelectorPayload |
SelectorModelMap
Ƭ SelectorModelMap: object
Defined in packages/redux-data-model/src/baseTypes.ts:68
Type declaration:
High Order Component (HOC) Functions
connectModel
▸ connectModel‹TStateProps, TDispatchProps, TOwnProps, TMergedProps›(models
: Model‹any›[], userProvidedMapStateToProps
: MapStateToPropsWithSelectors‹TStateProps, TOwnProps, any› | null, userProvidedMapDispatchToProps
: MapDispatchToPropsWithActionCreators‹TDispatchProps, TOwnProps› | null, mergeProps
: MergeProps‹TStateProps, TDispatchProps, TOwnProps, TMergedProps› | null | undefined, options?
: Record‹string, any›): function
Defined in packages/redux-data-model/src/redux/connectModel.ts:33
Equivalent to redux's connect function. This should be used when the hooks api is not desired or supported. Otherwise check useModelActions and useModelSelector up.
example
const ConnectedComponent = connectModel([modelA, modelB], mapStateToProps);
const ConnectedComponent = connectModel([modelA, modelB], mapStateToProps, mapDispatchToProps);
const ConnectedComponent = connectModel([modelA, modelB], null, mapDispatchToProps);
const ConnectedComponent = connectModel([modelA, modelB], mapStateToProps, mapDispatchToProps, mergeProps, options);
throws
ModelNotReduxInitializedError When model was not initialized on a combineModelReducers call.
throws
ModelNotSagaInitializedError When model was not initialized on a modelRootSaga call.
throws
KeyConflictInMergePropsError When the props passed from the parent component, mapStateToProps props,
or mapDispatchToProps props are conflicting (i.e. have the same name).
This check is ignored when a custom mergeProps function is provided.
Type parameters:
▪ TStateProps
▪ TDispatchProps
▪ TOwnProps
▪ TMergedProps
Parameters:
Name | Type | Default | Description |
---|---|---|---|
models | Model‹any›[] | - | An array of Model instances. |
userProvidedMapStateToProps | MapStateToPropsWithSelectors‹TStateProps, TOwnProps, any› | null | null | A mapToProps equivalent, which has a third argument with all selectors. |
userProvidedMapDispatchToProps | MapDispatchToPropsWithActionCreators‹TDispatchProps, TOwnProps› | null | null | A mapDispatchToProps equivalent, which has a third argument with all models' dispatchers (i.e. already dispatch bound). |
mergeProps | MergeProps‹TStateProps, TDispatchProps, TOwnProps, TMergedProps› | null | undefined | null | See react-redux documentation for mergeProps. |
options? | Record‹string, any› | - | See react-redux documentation for options. |
Returns: function
A connect HOC.
▸ ‹C›(component
: C): ConnectedComponent‹C, Omit‹GetProps‹C›, keyof Shared<TInjectedProps, GetProps
Type parameters:
▪ C: ComponentType‹Matching‹TInjectedProps, GetProps‹C›››
Parameters:
Name | Type |
---|---|
component | C |
React Hook Functions
useModelActions
▸ useModelActions‹ReducerPayloads, EffectPayloads›(model
: Model‹unknown, unknown, ReducerPayloads, EffectPayloads›): BoundNamespacedActionCreatorsMapObject‹ReducerPayloads & EffectPayloads›
Defined in packages/redux-data-model-hooks/src/useModelActions.ts:27
A react hook for returning already bound action creators for the provided model. If you don't want/need to use the hooks api, check connectModel up.
example
const modelActions = useModelActions(model);
throws
ModelNotReduxInitializedError When model was not initialized on a combineModelReducers call.
throws
ModelNotSagaInitializedError When model was not initialized on a modelRootSaga call.
Type parameters:
▪ ReducerPayloads
▪ EffectPayloads
Parameters:
Name | Type | Description |
---|---|---|
model | Model‹unknown, unknown, ReducerPayloads, EffectPayloads› | A model instance. |
Returns: BoundNamespacedActionCreatorsMapObject‹ReducerPayloads & EffectPayloads›
An object with already bound action creators. The bound action creators return a promise when invoked, which can be used to track if the action was properly processed (i.e. resolved) or caused an exception (i.e. rejected).
useModelSelector
▸ useModelSelector‹ReturnValue, State, SelectorPayloads›(model
: Model‹unknown, SelectorPayloads, unknown, unknown›, selectorFunc
: function): ReturnValue
Defined in packages/redux-data-model-hooks/src/useModelSelector.ts:19
A react hook for returning data from the provided model's state, by the means of one of its selectors. If you don't want/need to use the hooks api, check connectModel up.
example
const someDataFromState = useModelSelector(model, (state, selectors) => selectors.count(state));
throws
ModelNotReduxInitializedError When model was not initialized on a combineModelReducers call.
Type parameters:
▪ ReturnValue
▪ State
▪ SelectorPayloads
Parameters:
▪ model: Model‹unknown, SelectorPayloads, unknown, unknown›
A model instance.
▪ selectorFunc: function
A selector func, which will call one of the selectors in the provided model. The first argument must be the entire redux state, followed by the selectors map of the model.
▸ (state
: State, selectors
: SelectorModelMap‹any, SelectorPayloads›): ReturnValue
Parameters:
Name | Type |
---|---|
state | State |
selectors | SelectorModelMap‹any, SelectorPayloads› |
Returns: ReturnValue
Data from model's state.
Redux/Saga Setup Functions
bindModelActionCreators
▸ bindModelActionCreators(actionCreators
: ActionCreatorsMapObject‹any›, dispatch
: Dispatch): BoundNamespacedActionCreatorsMapObject
Defined in packages/redux-data-model/src/redux/bindModelActionCreators.ts:24
Turns an object whose values are action creators or nested objects with them, into an object with the same keys, but with every action creator wrapped into a dispatch call so they may be invoked directly. A Promise will be returned on every invocation, which can be used to track if the action was properly processed (i.e. resolved) or caused an exception (i.e. rejected).
Parameters:
Name | Type | Description |
---|---|---|
actionCreators | ActionCreatorsMapObject‹any› | a namespaced action creator's map object. This can have multiple levels of nesting, depending on the namespaces of the models involved. |
dispatch | Dispatch | A dispatch function available on the Store instance.. |
Returns: BoundNamespacedActionCreatorsMapObject
An object mimicking the original object, but with each function immediately dispatching the action returned by the corresponding action creator. And returning a Promise, which will resolve/ reject once done.
combineModelReducers
▸ combineModelReducers(models
: Model‹any›[]): ReducersMapObject
Defined in packages/redux-data-model/src/redux/combineModelReducers.ts:35
Returns a reducer map object that can be deconstructed into the combineReducers helper, from redux, so that redux is aware of any reducers produced by models.
example
const store = createStore(combineReducers({
...combineModelReducers([modelA, modelB]),
}), applyMiddleware(sagaMiddleware));
throws
DuplicatedModelNamespaceError When multiple models have the same namespace.
Parameters:
Name | Type | Description |
---|---|---|
models | Model‹any›[] | An array of Model instances. |
Returns: ReducersMapObject
A reducer's map object.
modelRootSaga
▸ modelRootSaga(models
: Model‹any›[]): SagaIterator
Defined in packages/redux-data-model/src/saga.ts:121
Returns a root saga generator that can be passed to sagaMiddleware's run function, so that redux-saga is aware of any sagas produced by models.
example
sagaMiddleware.run(() => modelRootSaga([modelA, modelB]));
Parameters:
Name | Type | Description |
---|---|---|
models | Model‹any›[] | An array of Model instances. |
Returns: SagaIterator
A root saga.