2.0.0 • Published 9 years ago
redux-simple-storage v2.0.0
redux-simple-storage
Save and load the state data to the local storage and file storage
Installation
npm install --save redux-simple-storageDevelopment
git clone https://github.com/ichigo4800/redux-simple-storage
cd redux-simple-storage
npm install
npm run buildUsage
Example 1 (Use the local storage)
Example of the most simple method of use. Save all of the state that have registered to reducers to local storage.
import storage from 'redux-simple-storage'
let store = createStore(
reducers,
applyMiddleware(
storage.saveState()
)
);
// state data load from local storage
store = storage.loadState(store);Example 2 (Use the file storage)
If you use file storage. have to set "storage_type" and "path" for config option.
import storage from 'redux-simple-storage'
// save and load file storage a file ("c:\abc\data.json")
storage.setConfig({
storage_type: 'file',
file_path: 'c:\abc',
file_name: 'data.json',
});
let store = createStore(
reducers,
applyMiddleware(
storage.saveState()
)
);
// state data load from file storage
store = storage.loadState(store);Example 3 (Use the white list filter)
import storage from 'redux-simple-storage'
const reducers = combineReducers({
stateTitle,
stateDate,
stateUser,
});
// save and load "stateTitle" and "stateDate"
storage.setConfig({
filter_type: 'whitelist',
filter_list: [
'stateTitle',
'stateDate',
],
});
let store = createStore(
reducers,
applyMiddleware(
storage.saveState()
)
);
store = storage.loadState(store);Example 4 (Use the black list filter)
import storage from 'redux-simple-storage'
const reducers = combineReducers({
stateTitle,
stateDate,
stateUser,
});
// save and load the state except "stateTitle"
storage.setConfig({
filter_type: 'blacklist',
filter_list: [
'stateTitle',
],
});
let store = createStore(
reducers,
applyMiddleware(
storage.saveState()
)
);
store = storage.loadState(store);Example 5 (Use multi storage)
State saved using both of local storage and file storage in the below example.
import storage from 'redux-simple-storage'
const reducers = combineReducers({
stateTitle,
stateDate,
stateUser,
});
// stateTitle use the local storage
const storageA = {
filter_type: 'whitelist',
filter_list: [
'stateTitle',
],
};
// stateDate use the file storage ("c:\abc\date.json")
const storageB = {
storage_type: 'file',
file_path: 'c:\abc',
file_name: 'date.json',
filter_type: 'whitelist',
filter_list: [
'stateDate',
],
};
// stateUser use different file storage a file with the "storageB" ("c:\abc\user.json")
const storageC = {
storage_type: 'file',
file_path: 'c:\abc',
file_name: 'user.json',
filter_type: 'whitelist',
filter_list: [
'stateUser',
],
};
storage.setConfig(
storageA,
storageB,
storageC
);
let store = createStore(
reducers,
applyMiddleware(
storage.saveState()
)
);
// state data load from local storage and file storage
store = storage.loadState(store);API
.saveState()
.loadState(createStore())
.setConfig({options})
| options | type | default | description |
|---|---|---|---|
| storage_type | string | "local" | "local" or "file" |
| filter_type | string | "blacklist" | "whitelist" or "blacklist" |
| filter_list | array | [] | set the state name to filter |
| file_path | string | "" | If you use file storage. have to set path value |
| file_name | string | "redux-states.json" | Can set the file name for save the file |
| local_key | string | "redux-states" | local storage key name |
License
WTFPL
2.0.0
9 years ago
1.6.8
9 years ago
1.6.7
9 years ago
1.6.6
9 years ago
1.6.5
9 years ago
1.6.0
9 years ago
1.5.10
10 years ago
1.5.9
10 years ago
1.5.8
10 years ago
1.5.7
10 years ago
1.5.6
10 years ago
1.5.5
10 years ago
1.5.4
10 years ago
1.5.3
10 years ago
1.5.2
10 years ago
1.5.1
10 years ago
1.5.0
10 years ago
1.0.16
10 years ago
1.0.15
10 years ago
1.0.14
10 years ago
1.0.13
10 years ago
1.0.12
10 years ago
1.0.11
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago
0.0.1
10 years ago