1.0.12 • Published 2 years ago

redux-data-module v1.0.12

Weekly downloads
17
License
MIT
Repository
github
Last release
2 years ago

Base Module


Options

moduleKey : string (required)

This key is used to generate the action key prefix in case it was not specified. e.g.: mymodule, mymodule/submodule

reducerKey : string (optional, defaults to moduleKey)

This key is used to retrieve the module state starting from the root of the state. It supports nested keys. e.g.: mymodule, mymodule.submodule

initialState : object (optional)

This object represents the initial state of the module.

actionKeyPrefix : string (optional)

This key is used to generate a prefix for action keys. It can be any string you want. If omitted, it will be generated from the moduleKey.

registerSelector(selectorName, selectState, selector)

This function is used to register a selector on the module.

  • selectorName : string Name of the selector
  • selectState : func | func This function receives the root state and the module state as parameters. This function must return a value.
  • selector : func This function receives the values returned in selectState in the order they were called. This function must return a value

registerActionKey(actionKey)

This function is used to register an action key, using the module's actionKeyPrefix.

  • actionKey : string

Examples


Creating a counter that keeps track of a value and let's us increment and decrement it.

const CounterModule = new BaseModule({
    moduleKey: 'counter',
    initialState: {
        value: 0
    }
})

Counter.registerSelector('value', (state, moduleState) => moduleState.value, (value) => value)

Counter.registerActionKey('increment')
Counter.actions.increment = () => dispatch => dispatch({ type: Counter.actionKeys.increment })
Counter.reducers[Counter.actionKeys.increment] = (state) => ({ ...state, value: state.value + 1 })

Counter.registerActionKey('decrement')
Counter.actions.decrement = () => dispatch => dispatch({ type: Counter.actionKeys.decrement })
Counter.reducers[Counter.actionKeys.decrement] = (state) => ({ ...state, value: state.value - 1 })
1.0.12

2 years ago

1.0.9

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago