Try any Node.js package right in your browser

Share this code:

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including redux-check-task with all npm packages installed. Try it out:

redux-check-task v0.0.11

redux-check-task

A redux state manager for async tasks and checks. A task is a unit of async work that should only be run under certain conditions or in certains ways. A check is two tasks, one for the work and one to check if the work should done. Provides reducers and action creators to handle task state and to dispatch task or check actions.

Installing

Running the tests

Usage

create a task reducer

note: A '.' delimited state key must be supplied to the task reducer creator. This is used to find the task in a nested state and to ensure this is the only task that responds to it's action (i.e. - app.myReducer.myWork)

create a check reducer

note: A '.' delimited state key must be supplied to the check reducer creator. This is used to find the check in a nested state and to ensure this is the only check that responds to it's action (i.e. - app.myReducer.myWork)

taskOnlyOnce - bool indicating whether to perform the task more than one time (defaults to false)

task/check state

task state

{
...state,
myWork: {
stateKey, // string containing the state key used to dispatch this task (will be 'myWork' in this case)
meta: {
performing, // bool indicating whether the task is currently in progress
complete, // bool indicating whether the task is finished
timing: {
started: // Date instance containing when the task was executed
duration: // number containing how long the task took in ms
}
},
results // the value resolved by the task
}
}

once a task or check action is dispatched it will return a Promise with results of the run:

dispatch(createTaskAction({
stateKey: 'myWork',
task: (dispatch, getState) => Promise.resolve({ some: 'data' })
})).then(({
stateKey, // string containing the state key used to dispatch this task
onlyOnce, // bool indicating whether the task will be executed more than once,
alreadyPerformed, // bool indicating whether the task was executed by a previous dispatch,
performance: { // if a task is configured to only run one time and it has already been executed, the performance property will be undefined
timing: {
started: Date instance containing when the task was executed
duration: number containing how long the task took in ms
},
results // the value resolved by the task - will be { some: 'data' }
}
}) => {})

License

This project is licensed under the MIT License - see the LICENSE.md file for details