API - Classes - Model
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.
Class: Model ‹State, SelectorPayloads, ReducerPayloads, EffectPayloads›
Models are the most basic data structure/abstraction in this library. They require a set of options to be provided when initializing them. The model will be used to generate the action types, actions, reducers, dispatchers, and sagas, based on the model's options that were provided.
Type parameters
▪ State
▪ SelectorPayloads
▪ ReducerPayloads
▪ EffectPayloads
Hierarchy
- Model
Index
Constructors
Properties
Accessors
- blockingEffects
- effects
- isReduxInitialized
- isSagaInitialized
- namespace
- reducers
- reduxSagas
- selectors
- state
Methods
Constructors
constructor
+ new Model(options
: ModelOptions‹State, SelectorPayloads, ReducerPayloads, EffectPayloads›): Model
Defined in packages/redux-data-model/src/model.ts:233
Creates a model instance.
example
const counterModel = new Model({
namespace: 'counter',
state: {
count: 0,
},
selectors: {
count: (state) => state.count,
},
reducers: {
increment(state) {
state.count += 1;
},
decrement(state) {
state.count -= 1;
},
setCount(state, { value }) {
state.count = value;
},
},
// effects: {...}
// blockingEffects: {...}
});
throws
NamespaceIsntAStringError When namespace isn't a string.
throws
EmptyNamespaceError When namespace is an empty string.
throws
InvalidNamespaceError When namespace has invalid characters.
throws
DuplicatedActionTypesError When reducer and/or effect action types are duplicated.
throws
BlockingEffectWithoutMatchingEffectError When blocking effect action types don't have a matching
effect action type.
Parameters:
Name | Type | Description |
---|---|---|
options | ModelOptions‹State, SelectorPayloads, ReducerPayloads, EffectPayloads› | A model's options. |
Returns: Model
Properties
Static
disableInitializationChecks
▪ disableInitializationChecks: boolean = false
Defined in packages/redux-data-model/src/model.ts:217
Whether ModelNotReduxInitializedError and ModelNotSagaInitializedError should be thrown when the model is used without it being integrated with Redux/Saga yet. Normally you only want to disable initialization checks in your tests, given they help developers to find out common mistakes soon.
Static
disableProxyChecks
▪ disableProxyChecks: boolean = false
Defined in packages/redux-data-model/src/model.ts:224
Whether UndefinedReducerOrEffectError, UndefinedSelectorError, UndefinedSagaEffectError, and UndefinedBlockingSagaEffectError should be thrown when a accessing properties that were not defined. Normally you only want to disable proxy checks in your tests, given they help developers to find out common mistakes soon.
Accessors
blockingEffects
• get blockingEffects(): BlockingEffectMap‹BlockingSagaEffects, EffectPayloads›
Defined in packages/redux-data-model/src/model.ts:579
Returns the blocking effects as provided in the constructor.
Returns: BlockingEffectMap‹BlockingSagaEffects, EffectPayloads›
A blocking effect map.
effects
• get effects(): EffectMap‹SagaEffects, ReducerPayloads, EffectPayloads›
Defined in packages/redux-data-model/src/model.ts:570
Returns the effects as provided in the constructor.
Returns: EffectMap‹SagaEffects, ReducerPayloads, EffectPayloads›
An effect map.
isReduxInitialized
• get isReduxInitialized(): boolean
Defined in packages/redux-data-model/src/model.ts:516
Returns whether the model was initialized on a combineModelReducers call.
Returns: boolean
A boolean.
isSagaInitialized
• get isSagaInitialized(): boolean
Defined in packages/redux-data-model/src/model.ts:525
Returns whether the model was initialized on a modelRootSaga call.
Returns: boolean
A boolean.
namespace
• get namespace(): string
Defined in packages/redux-data-model/src/model.ts:534
Returns the namespace as provided in the constructor.
Returns: string
A string.
reducers
• get reducers(): ReducerMap‹State, ReducerPayloads›
Defined in packages/redux-data-model/src/model.ts:561
Returns the reducers as provided in the constructor.
Returns: ReducerMap‹State, ReducerPayloads›
A reducer function.
reduxSagas
• get reduxSagas(): Saga[]
Defined in packages/redux-data-model/src/model.ts:501
Returns an array of sagas, one for each of the declared normal effects/blocking effects. Normal effects will default to taking every action and calling its respective effect, unless overridden by a blocking effect.
throws
NonCompatibleActionError When bindModelActionCreators was not used to bind the action creators.
Returns: Saga[]
An array of sagas.
selectors
• get selectors(): SelectorMap‹Immutable‹State›, SelectorPayloads›
Defined in packages/redux-data-model/src/model.ts:552
Returns the selectors as provided in the constructor.
Returns: SelectorMap‹Immutable‹State›, SelectorPayloads›
A selectors map.
state
• get state(): Immutable‹State›
Defined in packages/redux-data-model/src/model.ts:543
Returns the initial state as provided in the constructor.
Returns: Immutable‹State›
An initial state.
Methods
actionCreators
▸ actionCreators(): ActionCreatorsMapObject‹ReducerPayloads & EffectPayloads›
Defined in packages/redux-data-model/src/model.ts:360
Returns an object with action creators, one for each of the declared reducers and effects. Only useful for testing purposes, read the docs section on testing for more info, or when you need to process actions from a different model's reducers/effects. Being the latter a common approach when dispatching another model's actions within your effects.
Returns: ActionCreatorsMapObject‹ReducerPayloads & EffectPayloads›
An action creator's map object.
actionTypes
▸ actionTypes(): ActionTypesMapObject‹ReducerPayloads & EffectPayloads›
Defined in packages/redux-data-model/src/model.ts:337
Returns an object with action types, one for each of the declared reducers and effects. Only useful for testing purposes, read the docs section on testing for more info, or when you need to process actions from a different model's reducers/effects. Being the latter a common approach when normalising data.
Returns: ActionTypesMapObject‹ReducerPayloads & EffectPayloads›
An action type's map object.