1
- [ redux-storage] [ ]
2
- =================
1
+ # [ redux-storage] [ ]
3
2
4
3
[ ![ build] ( https://travis-ci.org/michaelcontento/redux-storage.svg )] ( https://travis-ci.org/michaelcontento/redux-storage )
5
4
[ ![ 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.
15
14
## Features
16
15
17
16
* 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 `
20
20
* Storage engines can be async
21
21
* Load and save actions that can be observed
22
22
* [ SAVE] [ ] : ` { type: 'REDUX_STORAGE_SAVE', payload: /* state tree */ } `
@@ -25,13 +25,16 @@ Save and load the [Redux][] state with ease.
25
25
* [ debounce] [ ] : batch multiple save operations
26
26
* [ filter] [ ] : only store a subset of the whole state tree
27
27
* [ immutablejs] [ ] : load parts of the state tree as [ Immutable] [ ] objects
28
- * [ migrate] [ ] : Versioned storage with migrations
28
+ * [ migrate] [ ] : versioned storage with migrations
29
29
* Black- and whitelist actions from issuing a save operation
30
30
31
31
## Installation
32
32
33
33
npm install --save redux-storage
34
34
35
+ And you need to install at least one [ redux-storage-engine] [ npm-engine ] , as
36
+ [ redux-storage] [ ] is only the * "management core"* .
37
+
35
38
## Usage
36
39
37
40
``` js
@@ -51,7 +54,7 @@ const reducer = storage.reducer(combineReducers(reducers));
51
54
// Now it's time to decide which storage engine should be used
52
55
//
53
56
// 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 ' ;
55
58
const engine = createEngine (' my-save-key' );
56
59
57
60
// And with the engine we can create our middleware function. The middleware
@@ -88,37 +91,12 @@ load(store)
88
91
89
92
## Details
90
93
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
104
95
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
122
100
123
101
### Actions
124
102
@@ -170,82 +148,41 @@ import { SHOULD_SAVE } from './constants';
170
148
const middleware = createMiddleware (engine, [], [ SHOULD_SAVE ]);
171
149
```
172
150
173
- ### Decorators
151
+ ## License
174
152
175
- Decorators simply wrap your engine instance and modify/enhance it's behaviour.
153
+ The MIT License (MIT)
176
154
177
- #### Filter
155
+ Copyright (c) 2015 Michael Contento
178
156
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:
233
163
234
- ## Todo
164
+ The above copyright notice and this permission notice shall be included in all
165
+ copies or substantial portions of the Software.
235
166
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.
237
173
174
+ [ npm-engine ] : https://www.npmjs.com/browse/keyword/redux-storage-engine
175
+ [ npm-decorator ] : https://www.npmjs.com/browse/keyword/redux-storage-decorator
238
176
[ Redux ] : https://github.com/gaearon/redux
239
177
[ Immutable ] : https://github.com/facebook/immutable-js
240
178
[ redux-storage ] : https://github.com/michaelcontento/redux-storage
241
179
[ 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
245
183
[ LOAD ] : https://github.com/michaelcontento/redux-storage/blob/master/src/constants.js#L1
246
184
[ 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