Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tanhauhau/redux-offline-sauce
Some aesthetic toppings for your Redux Offline meal.
https://github.com/tanhauhau/redux-offline-sauce
redux redux-offline reduxsauce
Last synced: 21 days ago
JSON representation
Some aesthetic toppings for your Redux Offline meal.
- Host: GitHub
- URL: https://github.com/tanhauhau/redux-offline-sauce
- Owner: tanhauhau
- License: mit
- Created: 2017-04-14T14:48:07.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-04-14T15:05:57.000Z (over 7 years ago)
- Last Synced: 2024-09-22T00:24:27.669Z (about 1 month ago)
- Topics: redux, redux-offline, reduxsauce
- Language: JavaScript
- Size: 61.5 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-offline-sauce
[![npm version](https://badge.fury.io/js/redux-offline-sauce.svg)](https://badge.fury.io/js/redux-offline-sauce)
[![Build Status](https://travis-ci.org/tanhauhau/redux-offline-sauce.svg?branch=master)](https://travis-ci.org/tanhauhau/redux-offline-sauce)> Some aesthetic toppings for your Redux Offline meal.
# Installation
```bash
$ npm install --save redux-offline-sauce
```## Overview
What is Redux Offline? [Redux Offline](https://github.com/jevakallio/redux-offline) is a battle-tested offline-first architecture.
[redux-offline-sauce](https://github.com/tanhauhau/redux-offline-sauce) inspired by [reduxsauce](https://github.com/skellock/reduxsauce) aims to provide tools to work with [Redux Offline](https://github.com/jevakallio/redux-offline).
## Usage
### createOfflineActions
Like `createActions` from [reduxsauce](https://github.com/skellock/reduxsauce), `createOfflineActions` returns `Types` and `Creators`.
When creating a new offline action, you most probably have written redux actions such as `{ type: 'DELETE_OBJ', id: 1}` or redux thunk `(id) => ({ type: 'UPDATE_OBJ', id: id })`.
`createOfflineActions` allows you to specify a redux action or redux thunk or mixture of both in `commit` and `rollback` of the offline action.**Example: **
```js
const { Types, Creators } = createActions(NormalActionsConfig);
const { Types: OfflineTypes, Creators: OfflineCreators } = createOfflineActions({
createOfflineObj: {
offline: Creators.createObj,
effect: { url: '/api/create', method: 'POST', body: { a: 1, b: 2 } },
commit: Creators.updateObj,
rollback: Creators.deleteObj,
},
createOfflineObj2: {
offline: Creators.createObj,
effect: { url: '/api/create', method: 'POST', body: { a: 1, b: 2 } },
commit: {
action: Creators.updateObj,
meta: ['id', { delay: 10, retries: 5 }],
},
rollback: { type: 'ROLLBACK', time: 'now', strategy: 'merge' },
meta: {
otherMeta: {
a: 2,
b: 3,
},
},
},
});OfflineTypes
/*
{
CREATE_OFFLINE_OBJ: CREATE_OFFLINE_OBJ,
CREATE_OFFLINE_OBJ2: CREATE_OFFLINE_OBJ2
}
*/OfflineCreators.createOfflineObj(999, 'nine-nine-nine')
/*
{
type: 'CREATE_OBJ',
id: 999,
name: 'nine-nine-nine',
payload: { id: 999, name: 'nine-nine-nine' },
meta: {
offline: {
effect: { url: '/api/create', method: 'POST', body: { id: 999, name: 'nine-nine-nine', a: 1, b: 2 } },
commit: { type: 'UPDATE_OBJ', id: 999, name: 'nine-nine-nine', meta: {} },
rollback: { type: 'DELETE_OBJ', id: 999, meta: {} },
},
}
}
*/OfflineCreators.createOfflineObj2(999, 'nine-nine-nine')
/*
{
type: 'CREATE_OBJ',
id: 999,
name: 'nine-nine-nine',
payload: { id: 999, name: 'nine-nine-nine' },
meta: {
offline: {
effect: { url: '/api/create', method: 'POST', body: { id: 999, name: 'nine-nine-nine', a: 1, b: 2 } },
commit: { type: 'UPDATE_OBJ', id: 999, name: 'nine-nine-nine', meta: { id: 999, delay: 10, retries: 5 } },
rollback: { type: 'ROLLBACK', time: 'now', strategy: 'merge' },
},
otherMeta: {
a: 2,
b: 3,
},
}
}
*/```
# License
MIT