Simple syncing between ngrx store and localStorage, IndexedDB or WebSQL.
ngrx-store-persist
depends on @ngrx/store and Angular 2+.
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.