ngrx-store-persist
Version:
ngrx-store-persist depends on @ngrx/store and angular 2+
43 lines (36 loc) • 1.13 kB
Markdown
Simple syncing between ngrx store and localStorage, IndexedDB or WebSQL.
`ngrx-store-persist` depends on [@ngrx/store](https://github.com/ngrx/store) and [Angular 2+](https://github.com/angular/angular).
```bash
npm install ngrx-store-persist --save
```
```ts
// 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`:
```ts
// app.module.ts
import { storageSyncMetaReducer } from 'ngrx-store-persist';
StoreModule.forRoot(rootReducer, { metaReducers: [storageSyncMetaReducer] }),
```
* `keys` (required) State keys to sync with storage.
* `driver` (optional) by default equals localForage.LOCALSTORAGE. Also can be localForage.WEBSQL, localForage.INDEXEDDB.