ngrx-store-persist
v1.0.24
Published
ngrx-store-persist depends on @ngrx/store and angular 2+
Downloads
1,993
Maintainers
Readme
ngrx-store-persist
Simple syncing between ngrx store and localStorage, IndexedDB or WebSQL.
Dependencies
ngrx-store-persist
depends on @ngrx/store and Angular 2+.
Usage
npm install ngrx-store-persist --save
// main.ts
import { NgModule } from '@angular/core';
import {
getAllDataFromLocalForage,
default as localForage,
} from 'ngrx-store-persist';
getAllDataFromLocalForage({
driver: localForage.INDEXEDDB,
keys: [
'user',
'posts'
],
}).then(() => {
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch(err => console.log(err));
});
Also need to add storageSyncMetaReducer
to metaReducers
:
// app.module.ts
import { storageSyncMetaReducer } from 'ngrx-store-persist';
StoreModule.forRoot(rootReducer, { metaReducers: [storageSyncMetaReducer] }),
##Config
keys
(required) State keys to sync with storage.driver
(optional) by default equals localForage.LOCALSTORAGE. Also can be localForage.WEBSQL, localForage.INDEXEDDB.