redux-offline-actions
v1.0.0
Published
Flux standard action utilities for use with redux-offline applications.
Downloads
6
Maintainers
Readme
redux-offline-actions
Flux Standard Action utilities for Redux Offline.
Table of Contents
Getting Started
Installation
$ npm install --save redux-offline-actions
or
$ yarn add redux-offline-actions
The npm package provides a CommonJS build for use in Node.js, and with bundlers like Webpack and Browserify. It also includes an ES modules build that works well with Rollup and Webpack2's tree-shaking.
The UMD build exports a global called window.ReduxOfflineActions
if you add it to your page via a <script>
tag. We don’t recommend UMD builds for any serious application, as most of the libraries complementary to Redux are only available on npm.
Usage
import { handleActions, combineActions } from 'redux-actions'
import { createOfflineAction } from 'redux-offline-actions'
const defaultState = [];
const createTodo = createOfflineAction(
'CREATE_TODO',
text => text,
text => {url: '/todo', method: 'post', args: {text}},
'CREATE_TODO_COMMIT',
'CREATE_TODO_ROLLBACK'
});
const reducer = handleActions({
['CREATE_TODO']: (state, { payload: { text } }) => [...state, text],
['CREATE_TODO_COMMIT']: (state, { meta: { text } }) => state.map(x => x === text ? {text, saved: true} : x),
['CREATE_TODO_ROLLBACK'] => (state, { meta: { text } }) => state.filter(x => x !== text)
}, defaultState);
export default reducer;
Support and Feedback
If you find a bug or have a question, please submit an issue in Github directly. redux-offline-actions Issues
If you're interested in contributing, please check out the Contribution Instructions.