ngrx-store-localstorage
Advanced tools
Comparing version 0.3.0 to 1.0.0
{ | ||
"name": "ngrx-store-localstorage", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"description": "State and local storage syncing for @ngrx/store", | ||
"main": "./dist/index.js", | ||
"scripts": { | ||
"build_dist": "rimraf dist && tsc", | ||
"prepublish": "npm run build_dist", | ||
"clean:test": "rimraf tmp", | ||
"clean:dist": "rimraf dist", | ||
"lint": "tslint src/**.ts", | ||
"build_tests": "tsc -p spec", | ||
"exec_tests": "jasmine", | ||
"test": "tsc -p spec && jasmine && npm run clean:test", | ||
"typings": "typings install" | ||
}, | ||
"repository": { | ||
@@ -21,3 +9,9 @@ "type": "git", | ||
}, | ||
"keywords": ["redux", "ngrx", "store", "localstorage", "rxjs"], | ||
"keywords": [ | ||
"redux", | ||
"ngrx", | ||
"store", | ||
"localstorage", | ||
"rxjs" | ||
], | ||
"author": "Brian Troncone", | ||
@@ -29,25 +23,20 @@ "license": "MIT", | ||
"homepage": "https://github.com/btroncone/ngrx-store-localstorage#readme", | ||
"dependencies": { | ||
"deepmerge": "^3.2.0", | ||
"tslib": "^2.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@ngrx/store": "^4.0.0" | ||
"@ngrx/store": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0" | ||
}, | ||
"devDependencies": { | ||
"@angular/core": "^2.4.7", | ||
"@ngrx/core": "^1.2.0", | ||
"@ngrx/store": "^2.2.1", | ||
"@types/core-js": "^0.9.35", | ||
"@types/crypto-js": "^3.1.33", | ||
"@types/jasmine": "^2.5.47", | ||
"@types/node": "^7.0.18", | ||
"crypto-js": "^3.1.9-1", | ||
"es6-promise": "^3.0.2", | ||
"es6-shim": "^0.35.0", | ||
"jasmine": "^2.4.1", | ||
"jasmine-core": "^2.4.1", | ||
"rimraf": "^2.5.4", | ||
"rxjs": "^5.1.1", | ||
"tslint": "^4.0.2", | ||
"typescript": "^2.1.4", | ||
"zone.js": "^0.7.7" | ||
"lint-staged": { | ||
"*.ts": "tslint --fix" | ||
}, | ||
"typings": "./dist/index.d.ts" | ||
"main": "bundles/ngrx-store-localstorage.umd.js", | ||
"module": "fesm2015/ngrx-store-localstorage.js", | ||
"es2015": "fesm2015/ngrx-store-localstorage.js", | ||
"esm2015": "esm2015/ngrx-store-localstorage.js", | ||
"fesm2015": "fesm2015/ngrx-store-localstorage.js", | ||
"typings": "ngrx-store-localstorage.d.ts", | ||
"metadata": "ngrx-store-localstorage.metadata.json", | ||
"sideEffects": false | ||
} |
# ngrx-store-localstorage | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) | ||
[![CircleCI](https://circleci.com/gh/btroncone/ngrx-store-localstorage.svg?style=svg)](https://circleci.com/gh/btroncone/ngrx-store-localstorage) | ||
Simple syncing between ngrx store and local storage. | ||
## Dependencies | ||
`ngrx-store-localstorage` depends on [@ngrx/store](https://github.com/ngrx/store) and [Angular 2+](https://github.com/angular/angular). | ||
## Usage | ||
```bash | ||
npm install ngrx-store-localstorage --save | ||
``` | ||
**UPDATE FOR NGRX 4** | ||
1. Wrap localStorageSync in an exported function. | ||
2. Include in your meta-reducers array in `StoreModule.forRoot`. | ||
```ts | ||
@@ -43,9 +49,13 @@ import { NgModule } from '@angular/core'; | ||
## API | ||
### `localStorageSync(config: LocalStorageConfig): Reducer` | ||
Provide state (reducer) keys to sync with local storage. *Returns a meta-reducer*. | ||
#### Arguments | ||
* `config` An object that matches with the `LocalStorageConfig` interface, `keys` is the only required property. | ||
### **LocalStorageConfig** | ||
An interface defining the configuration attributes to bootstrap `localStorageSync`. The following are properties which compose `LocalStorageConfig`: | ||
@@ -57,3 +67,3 @@ * `keys` (required) State keys to sync with local storage. The keys can be defined in two different formats: | ||
* An array of properties which should be synced. This allows for the partial state sync (e.g. `localStorageSync({keys: [{todos: ['name', 'status'] }, ... ]})`). | ||
* An array of properties which should be synced. This allows for the partial state sync (e.g. `localStorageSync({keys: [{todos: ['name', 'status'] }, ... ]})`). Note: this config cannot go any deeper. So you cannot specify another object inside of the `todos` array for example. | ||
@@ -64,52 +74,38 @@ * A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse). | ||
* serialize: A function that takes a state object and returns a plain json object to pass to json.stringify. | ||
* `serialize`: A function that takes a state object and returns a plain json object to pass to json.stringify. | ||
* deserialize: A function that takes that takes the raw JSON from JSON.parse and builds a state object. | ||
* `deserialize`: A function that takes that takes the raw JSON from JSON.parse and builds a state object. | ||
* replacer: A replacer function as specified in the [JSON.stringify documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). | ||
* `replacer`: A replacer function as specified in the [JSON.stringify documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). | ||
* space: The space value to pass JSON.stringify. | ||
* `space`: The space value to pass JSON.stringify. | ||
* reviver: A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse). | ||
* `reviver`: A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse). | ||
* filter: An array of properties which should be synced (same format as the stand-alone array specified above). | ||
* `filter`: An array of properties which should be synced (same format as the stand-alone array specified above). | ||
* `encrypt`: A function that takes a state string and returns an encrypted version of that string. | ||
e.g. `(state: string) => btoa(state)` | ||
* `decrypt`: A function that takes a state string and returns a decrypted version of that string. | ||
e.g. `(state: string) => atob(state)` | ||
* `rehydrate` (optional) `boolean`: Pull initial state from local storage on startup, this will default to `false`. | ||
* `storage` (optional) `Storage`: Specify an object that conforms to the [Storage interface](https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L9708) to use, this will default to `localStorage`. | ||
* `storage` (optional) `Storage`: Specify an object that conforms to the [Web Storage API interface](https://developer.mozilla.org/en-US/docs/Web/API/Storage) to use, this will default to `localStorage`. | ||
* `removeOnUndefined` (optional) `boolean`: Specify if the state is removed from the storage when the new value is undefined, this will default to `false`. | ||
* `storageKeySerializer` (optional) `(key: string) => string`: Сustom serialize function for storage keys, used to avoid Storage conflicts. | ||
* `storageKeySerializer` (optional) `(key: string) => string`: Custom serialize function for storage keys, used to avoid Storage conflicts. | ||
* `restoreDates` \(*boolean? = true*): Restore serialized date objects. If you work directly with ISO date strings, set this option to `false`. | ||
* `syncCondition` (optional) `(state) => boolean`: When set, sync to storage medium will only occur when this function returns a true boolean. Example: `(state) => state.config.syncToStorage` will check the state tree under config.syncToStorage and if true, it will sync to the storage. If undefined or false it will not sync to storage. Often useful for "remember me" options in login. | ||
* `checkStorageAvailability` \(*boolean? = false*): Specify if the storage availability checking is expected, i.e. for server side rendering / Universal. | ||
* `mergeReducer` (optional) `(state: any, rehydratedState: any, action: any) => any`: Defines the reducer to use to merge the rehydrated state from storage with the state from the ngrx store. If unspecified, defaults to performing a full deepmerge on an `INIT_ACTION` or an `UPDATE_ACTION`. | ||
Usage: `localStorageSync({keys: ['todos', 'visibilityFilter'], storageKeySerializer: (key) => 'cool_' + key, ... })`. In this example `Storage` will use keys `cool_todos` and `cool_visibilityFilter` keys to store `todos` and `visibilityFilter` slices of state). The key itself is used by default - `(key) => key`. | ||
--- | ||
### ~~`localStorageSyncAndClean(keys: any[], rehydrate: boolean = false, removeOnUndefined: boolean = false): Reducer`~~ | ||
**This function is deprecated and soon will be removed, please use _localStorageSync(LocalStorageConfig)_.** | ||
## Release Notes / Changelog | ||
A shorthand that wraps the functionalities of `localStorageSync` and asumes `localStorage` as the storage. | ||
From version 10 onwards, check [GitHub Releases](https://github.com/btroncone/ngrx-store-localstorage/releases) for release notes. For older versions check the [CHANGELOG.md](./CHANGELOG.md). | ||
#### Arguments | ||
## Contributing | ||
* `keys` State keys to sync with local storage. The keys can be defined in two different formats: | ||
* \(*string[]*): Array of strings representing the state (reducer) keys. Full state will be synced (e.g. `localStorageSync(['todos'])`). | ||
See [CONTRIBUTING.md](./CONTRIBUTING.md) for instructions on how to contribute. | ||
* \(*object[]*): Array of objects where for each object the key represents the state key and the value represents custom serialize/deserialize options. This can be one of the following: | ||
* An array of properties which should be synced. This allows for the partial state sync (e.g. `localStorageSync([{todos: ['name', 'status'] }, ... ])`). | ||
* A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse). | ||
* An object with properties that specify one or more of the following: | ||
* serialize: A function that takes a state object and returns a plain json object to pass to json.stringify. | ||
* deserialize: A function that takes that takes the raw JSON from JSON.parse and builds a state object. | ||
* replacer: A replacer function as specified in the [JSON.stringify documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). | ||
* space: The space value to pass JSON.stringify. | ||
* reviver: A reviver function as specified in the [JSON.parse documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse). | ||
* filter: An array of properties which should be synced (same format as the stand-along array specified above). | ||
* `rehydrateState` \(*boolean? = false*): Pull initial state from local storage on startup. | ||
* `removeOnUndefined` \(*boolean? = false*): Specify if the state is removed from the storage when the new value is undefined. |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
115463
0
17
3
771
109
2
+ Addeddeepmerge@^3.2.0
+ Addedtslib@^2.0.0
+ Added@angular/core@9.1.13(transitive)
+ Added@ngrx/store@9.2.1(transitive)
+ Addeddeepmerge@3.3.0(transitive)
+ Addedrxjs@6.6.7(transitive)
+ Addedtslib@2.6.3(transitive)
+ Addedzone.js@0.10.3(transitive)
- Removed@angular/core@5.2.11(transitive)
- Removed@ngrx/store@4.1.1(transitive)
- Removedrxjs@5.5.12(transitive)
- Removedsymbol-observable@1.0.1(transitive)
- Removedzone.js@0.8.29(transitive)