1- [ redux-storage] [ ]
2- =================
1+ # [ redux-storage] [ ]
32
43[ ![ build] ( https://travis-ci.org/michaelcontento/redux-storage.svg )] ( https://travis-ci.org/michaelcontento/redux-storage )
54[ ![ dependencies] ( https://david-dm.org/michaelcontento/redux-storage.svg )] ( https://david-dm.org/michaelcontento/redux-storage )
@@ -15,8 +14,9 @@ Save and load the [Redux][] state with ease.
1514## Features
1615
1716* Flexible storage engines
18- * [ localStorage] [ ] based on ` window.localStorage `
19- * [ reactNativeAsyncStorage] [ ] based on ` react-native/AsyncStorage `
17+ * [ localStorage] [ ] : based on window.localStorage
18+ * Or for environments without ` Promise ` support [ localStorageFakePromise] [ ]
19+ * [ reactNativeAsyncStorage] [ ] : based on ` react-native/AsyncStorage `
2020* Storage engines can be async
2121* Load and save actions that can be observed
2222 * [ SAVE] [ ] : ` { type: 'REDUX_STORAGE_SAVE', payload: /* state tree */ } `
@@ -25,13 +25,16 @@ Save and load the [Redux][] state with ease.
2525 * [ debounce] [ ] : batch multiple save operations
2626 * [ filter] [ ] : only store a subset of the whole state tree
2727 * [ immutablejs] [ ] : load parts of the state tree as [ Immutable] [ ] objects
28- * [ migrate] [ ] : Versioned storage with migrations
28+ * [ migrate] [ ] : versioned storage with migrations
2929* Black- and whitelist actions from issuing a save operation
3030
3131## Installation
3232
3333 npm install --save redux-storage
3434
35+ And you need to install at least one [ redux-storage-engine] [ npm-engine ] , as
36+ [ redux-storage] [ ] is only the * "management core"* .
37+
3538## Usage
3639
3740``` js
@@ -51,7 +54,7 @@ const reducer = storage.reducer(combineReducers(reducers));
5154// Now it's time to decide which storage engine should be used
5255//
5356// Note: The arguments to `createEngine` are different for every engine!
54- import createEngine from ' redux-storage/engines/reactNativeAsyncStorage ' ;
57+ import createEngine from ' redux-storage-engine-localStorage ' ;
5558const engine = createEngine (' my-save-key' );
5659
5760// And with the engine we can create our middleware function. The middleware
@@ -88,37 +91,12 @@ load(store)
8891
8992## Details
9093
91- ### Engines
92-
93- #### reactNativeAsyncStorage
94-
95- This will use ` AsyncStorage ` out of [ react-native] [ ] .
96-
97- ``` js
98- import createEngine from ' redux-storage/engines/reactNativeAsyncStorage' ;
99- const engine = createEngine (' my-save-key' );
100- ```
101-
102- ** Warning** : [ react-native] [ ] is * not* a dependency of [ redux-storage] [ ] ! You
103- have to install it separately.
94+ ### Engines & Decorators
10495
105- #### localStorage
106-
107- Stores everything inside ` window.localStorage ` .
108-
109- ``` js
110- import createEngine from ' redux-storage/engines/localStorage' ;
111- const engine = createEngine (' my-save-key' );
112- ```
113-
114- ** Warning** : ` localStorage ` does not expose a async API and every save/load
115- operation will block the JS thread!
116-
117- ** Warning** : Some browsers like IE<=11 does not support Promises. For this you
118- might use [ localStorageFakePromise] [ ] which should work too - ** BUT** other
119- parts of [ redux-storage] [ ] might depend on Promises too! So this is a possible
120- workaround for very limited cases only. The best solution is to use a polyfill
121- like [ es6-promise] [ ] .
96+ Both are published as own packages on npm. But as a convention all engines share
97+ the keyword [ redux-storage-engine] [ npm-engine ] and decorators can be found with
98+ [ redux-storage-decorator] [ npm-decorator ] . So it's pretty trivial to find all
99+ the additions to [ redux-storage] [ ] you need
122100
123101### Actions
124102
@@ -170,82 +148,41 @@ import { SHOULD_SAVE } from './constants';
170148const middleware = createMiddleware (engine, [], [ SHOULD_SAVE ]);
171149```
172150
173- ### Decorators
151+ ## License
174152
175- Decorators simply wrap your engine instance and modify/enhance it's behaviour.
153+ The MIT License (MIT)
176154
177- #### Filter
155+ Copyright (c) 2015 Michael Contento
178156
179- Use this decorator to write only part of your state tree to disk.
180-
181- It will write the state corresponding to the whitelisted keys minus the blacklisted ones.
182-
183- ``` js
184- import { decorators } from ' redux-storage'
185-
186- engine = decorators .filter (engine, [
187- ' whitelisted-key' ,
188- [' nested' , ' key' ],
189- [' another' , ' very' , ' nested' , ' key' ]
190- ],
191- [
192- ' backlisted-key' ,
193- [' nested' , ' blacklisted-key' ],
194- ]);
195- ```
196-
197- #### Debounce
198-
199- This decorator will delay the expensive save operation for the given ms. Every
200- new change to the state tree will reset the timeout!
201-
202- ``` js
203- import { decorators } from ' redux-storage'
204-
205- engine = decorators .debounce (engine, 1500 );
206- ```
207-
208- #### Immutablejs
209-
210- Convert parts of the state tree into [ Immutable] [ ] objects on ` engine.load ` .
211-
212- ``` js
213- import { decorators } from ' redux-storage'
214-
215- engine = decorators .immutablejs (engine, [
216- [' immutablejs-reducer' ],
217- [' plain-object-reducer' , ' with-immutablejs-key' ]
218- ]);
219- ```
220-
221- #### Migration
222-
223- Versioned storage with migrations.
224-
225- ``` js
226- import { decorators } from ' redux-storage'
227-
228- engine = decorators .migrate (engine, 3 );
229- engine .addMigration (1 , (state ) => { /* migration step for 1 */ return state; });
230- engine .addMigration (2 , (state ) => { /* migration step for 2 */ return state; });
231- engine .addMigration (3 , (state ) => { /* migration step for 3 */ return state; });
232- ```
157+ Permission is hereby granted, free of charge, to any person obtaining a copy of
158+ this software and associated documentation files (the "Software"), to deal in
159+ the Software without restriction, including without limitation the rights to
160+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
161+ the Software, and to permit persons to whom the Software is furnished to do so,
162+ subject to the following conditions:
233163
234- ## Todo
164+ The above copyright notice and this permission notice shall be included in all
165+ copies or substantial portions of the Software.
235166
236- - Write tests for everything!
167+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
169+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
170+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
171+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
172+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
237173
174+ [ npm-engine ] : https://www.npmjs.com/browse/keyword/redux-storage-engine
175+ [ npm-decorator ] : https://www.npmjs.com/browse/keyword/redux-storage-decorator
238176 [ Redux ] : https://github.com/gaearon/redux
239177 [ Immutable ] : https://github.com/facebook/immutable-js
240178 [ redux-storage ] : https://github.com/michaelcontento/redux-storage
241179 [ react-native ] : https://facebook.github.io/react-native/
242- [ localStorage ] : https://github.com/michaelcontento/redux-storage/blob/master/src/engines/ localStorage.js
243- [ localStorageFakePromise ] : https://github.com/michaelcontento/redux-storage/blob/master/src/engines/ localStorageFakePromise.js
244- [ reactNativeAsyncStorage ] : https://github.com/michaelcontento/redux-storage/blob/master/src/engines/ reactNativeAsyncStorage.js
180+ [ localStorage ] : https://github.com/michaelcontento/redux-storage-engine- localStorage
181+ [ localStorageFakePromise ] : https://github.com/michaelcontento/redux-storage-engine- localStorageFakePromise
182+ [ reactNativeAsyncStorage ] : https://github.com/michaelcontento/redux-storage-engine- reactNativeAsyncStorage
245183 [ LOAD ] : https://github.com/michaelcontento/redux-storage/blob/master/src/constants.js#L1
246184 [ SAVE ] : https://github.com/michaelcontento/redux-storage/blob/master/src/constants.js#L2
247- [ debounce ] : https://github.com/michaelcontento/redux-storage/blob/master/src/decorators/debounce.js
248- [ filter ] : https://github.com/michaelcontento/redux-storage/blob/master/src/decorators/filter.js
249- [ immutablejs ] : https://github.com/michaelcontento/redux-storage/blob/master/src/decorators/immutablejs.js
250- [ migrate ] : https://github.com/michaelcontento/redux-storage/blob/master/src/decorators/migrate.js
251- [ es6-promise ] : https://www.npmjs.com/package/es6-promise
185+ [ debounce ] : https://github.com/michaelcontento/redux-storage-decorator-debounce
186+ [ filter ] : https://github.com/michaelcontento/redux-storage-decorator-filter
187+ [ migrate ] : https://github.com/mathieudutour/redux-storage-decorator-migrate
188+ [ immutablejs ] : https://github.com/michaelcontento/redux-storage-decorator-immutablejs
0 commit comments