Random Number Generator¶
The RNG task handler allows generating random numbers outside of the reducer, so as not to make the reducer impure.
Task: Default¶
This task causes a random number to be generated and to be dispatched back to as payload of the prescribe action.
{
type: 'rng',
actions: {
result: string // action type to dispatch when the number has been generated
}
}
Actions¶
Event Type | Meta | Payload |
---|---|---|
result |
none | number |
Example¶
import {
addTask, reduceReducers, taskReducer
} from 'redux-agent'
const reducer = (state, action) => {
switch (action.type) {
case 'RANDOM_NUMBER':
return addTask(state, {
type: 'rng',
actions: {
result: 'RANDOM_NUMBER_RESULT'
}
})
case 'RANDOM_NUMBER_RESULT':
return {
...state,
randomNumber: action.payload
}
default:
return state
}
}
export default reduceReducers(reducer, taskReducer)