Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

Commit dd33fb2

Browse files
Merge pull request #91 from michaelcontento/extract-engines-and-decorators
Extract engines and decorators
2 parents 513b6a3 + 4a60262 commit dd33fb2

23 files changed

+59
-835
lines changed

.editorconfig

+6
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ indent_size = 4
77
indent_style = space
88
insert_final_newline = true
99
trim_trailing_whitespace = true
10+
11+
[package.json]
12+
indent_size = 2
13+
14+
[Makefile]
15+
indent_style = tab

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# build artefacts
22
/build/
3-
/engines/
43

54
# npm
65
/node_modules/

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3+
- "5.5"
34
- "5.4"
45
- "5.3"
56
- "5.2"

Makefile

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ node_modules/: package.json
1919
clean:
2020
echo "> Cleaning ..."
2121
rm -rf build/
22-
rm -rf engines/
2322

2423
mrproper: clean
2524
echo "> Cleaning deep ..."
@@ -32,7 +31,6 @@ mrproper: clean
3231
build: clean install
3332
echo "> Building ..."
3433
$(BIN)/babel src/ --out-dir build/
35-
mv -f ./build/engines ./
3634

3735
build-watch: clean install
3836
echo "> Building forever ..."
@@ -48,11 +46,11 @@ lint: install
4846

4947
test: install
5048
echo "> Testing ..."
51-
$(BIN)/mocca --require src/__tests__/init.js --globals localStorage
49+
$(BIN)/mocca
5250

5351
test-watch: install
5452
echo "> Testing forever ..."
55-
$(BIN)/mocca --require src/__tests__/init.js --globals localStorage --watch
53+
$(BIN)/mocca --watch
5654

5755
#
5856
# PUBLISH

README.md

+40-103
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
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';
5558
const 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';
170148
const 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

package.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-storage",
3-
"version": "2.2.0",
3+
"version": "3.0.0",
44
"description": "Persistence layer for redux with flexible backends",
55
"main": "build/index.js",
66
"jsnext:main": "src/index.js",
@@ -15,9 +15,6 @@
1515
"keywords": [
1616
"redux",
1717
"redux-middleware",
18-
"react-native",
19-
"promise",
20-
"middleware",
2118
"fsa",
2219
"flux-standard-action",
2320
"flux",
@@ -29,7 +26,6 @@
2926
"author": "Michael Contento <[email protected]>",
3027
"files": [
3128
"build/",
32-
"engines/",
3329
"src",
3430
"!**/__tests__/**"
3531
],
@@ -45,17 +41,15 @@
4541
"eslint": "^1.10.3",
4642
"eslint-config-michaelcontento": "^1.1.1",
4743
"eslint-plugin-mocha-only": "0.0.3",
44+
"immutable": "^3.7.6",
4845
"mocca": "^0.3.0",
4946
"release-it": "^2.3.1"
5047
},
5148
"dependencies": {
52-
"immutable": "^3.7.6",
5349
"lodash.isarray": "^4.0.0",
5450
"lodash.isfunction": "^3.0.7",
5551
"lodash.isobject": "^3.0.2",
5652
"lodash.merge": "^4.0.2",
57-
"lodash.set": "^4.0.0",
58-
"lodash.unset": "^4.1.0",
5953
"redux-actions": "^0.9.0"
6054
},
6155
"peerDependencies": {

src/__tests__/index-test.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import defaultImport from '../';
22
import * as fullImport from '../';
3-
import { LOAD, SAVE, createLoader, createMiddleware, decorators, reducer } from '../';
3+
import { LOAD, SAVE, createLoader, createMiddleware, reducer } from '../';
44

55
describe('index', () => {
66
it('should export everything by default', () => {
@@ -25,11 +25,6 @@ describe('index', () => {
2525
createMiddleware.should.be.a.func;
2626
});
2727

28-
it('should export decorators', () => {
29-
decorators.should.be.a.object;
30-
decorators.should.not.be.empty;
31-
});
32-
3328
it('should export reducer', () => {
3429
reducer.should.be.a.func;
3530
});

src/__tests__/init.js

-1
This file was deleted.

src/decorators/__tests__/debounce-test.js

-47
This file was deleted.

0 commit comments

Comments
 (0)