2.0.0 • Published 8 years ago

redux-simple-storage v2.0.0

Weekly downloads
1
License
WTFPL
Repository
-
Last release
8 years ago

redux-simple-storage

Save and load the state data to the local storage and file storage

Installation

npm install --save redux-simple-storage

Development

git clone https://github.com/ichigo4800/redux-simple-storage
cd redux-simple-storage
npm install
npm run build

Usage

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})

optionstypedefaultdescription
storage_typestring"local""local" or "file"
filter_typestring"blacklist""whitelist" or "blacklist"
filter_listarray[]set the state name to filter
file_pathstring""If you use file storage. have to set path value
file_namestring"redux-states.json"Can set the file name for save the file
local_keystring"redux-states"local storage key name

License

WTFPL

2.0.0

8 years ago

1.6.8

8 years ago

1.6.7

8 years ago

1.6.6

8 years ago

1.6.5

8 years ago

1.6.0

8 years ago

1.5.10

8 years ago

1.5.9

8 years ago

1.5.8

8 years ago

1.5.7

8 years ago

1.5.6

8 years ago

1.5.5

8 years ago

1.5.4

8 years ago

1.5.3

8 years ago

1.5.2

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.1

8 years ago