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,15 @@ 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
2928* Black- and whitelist actions from issuing a save operation
3029
3130## Installation
3231
3332 npm install --save redux-storage
3433
34+ And you need to install at least one [ redux-storage-engine] [ npm-engine ] , as
35+ [ redux-storage] [ ] is only the * "management core"* .
36+
3537## Usage
3638
3739``` js
@@ -51,7 +53,7 @@ const reducer = storage.reducer(combineReducers(reducers));
5153// Now it's time to decide which storage engine should be used
5254//
5355// Note: The arguments to `createEngine` are different for every engine!
54- import createEngine from ' redux-storage/engines/reactNativeAsyncStorage ' ;
56+ import createEngine from ' redux-storage-engine-localStorage ' ;
5557const engine = createEngine (' my-save-key' );
5658
5759// And with the engine we can create our middleware function. The middleware
@@ -88,37 +90,12 @@ load(store)
8890
8991## Details
9092
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.
93+ ### Engines & Decorators
10494
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] [ ] .
95+ Both are published as own packages on npm. But as a convention all engines share
96+ the keyword [ redux-storage-engine] [ npm-engine ] and decorators can be found with
97+ [ redux-storage-decorator] [ npm-decorator ] . So it's pretty trivial to find all
98+ the additions to [ redux-storage] [ ] you need
12299
123100### Actions
124101
@@ -170,82 +147,40 @@ import { SHOULD_SAVE } from './constants';
170147const middleware = createMiddleware (engine, [], [ SHOULD_SAVE ]);
171148```
172149
173- ### Decorators
150+ ## License
174151
175- Decorators simply wrap your engine instance and modify/enhance it's behaviour.
152+ The MIT License (MIT)
176153
177- #### Filter
154+ Copyright (c) 2015 Michael Contento
178155
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- ```
156+ Permission is hereby granted, free of charge, to any person obtaining a copy of
157+ this software and associated documentation files (the "Software"), to deal in
158+ the Software without restriction, including without limitation the rights to
159+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
160+ the Software, and to permit persons to whom the Software is furnished to do so,
161+ subject to the following conditions:
233162
234- ## Todo
163+ The above copyright notice and this permission notice shall be included in all
164+ copies or substantial portions of the Software.
235165
236- - Write tests for everything!
166+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
168+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
169+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
170+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
171+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
237172
173+ [ npm-engine ] : https://www.npmjs.com/browse/keyword/redux-storage-engine
174+ [ npm-decorator ] : https://www.npmjs.com/browse/keyword/redux-storage-decorator
238175 [ Redux ] : https://github.com/gaearon/redux
239176 [ Immutable ] : https://github.com/facebook/immutable-js
240177 [ redux-storage ] : https://github.com/michaelcontento/redux-storage
241178 [ 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
179+ [ localStorage ] : https://github.com/michaelcontento/redux-storage-engine- localStorage
180+ [ localStorageFakePromise ] : https://github.com/michaelcontento/redux-storage-engine- localStorageFakePromise
181+ [ reactNativeAsyncStorage ] : https://github.com/michaelcontento/redux-storage-engine- reactNativeAsyncStorage
245182 [ LOAD ] : https://github.com/michaelcontento/redux-storage/blob/master/src/constants.js#L1
246183 [ 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
184+ [ debounce ] : https://github.com/michaelcontento/redux-storage-decorator-debounce
185+ [ filter ] : https://github.com/michaelcontento/redux-storage-decorator-filter
186+ [ immutablejs ] : https://github.com/michaelcontento/redux-storage-decorator-immutablejs
0 commit comments