vuex-persistedstate
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -7,13 +7,13 @@ import { Store, MutationPayload } from "vuex"; | ||
} | ||
interface Options { | ||
interface Options<State> { | ||
key?: string; | ||
paths?: string[]; | ||
reducer?: (state: any, paths: string[]) => object; | ||
subscriber?: (store: typeof Store) => (handler: (mutation: any, state: any) => void) => void; | ||
reducer?: (state: State, paths: string[]) => object; | ||
subscriber?: (store: Store<State>) => (handler: (mutation: any, state: State) => void) => void; | ||
storage?: Storage; | ||
getState?: (key: string, storage: Storage) => any; | ||
setState?: (key: string, state: typeof Store, storage: Storage) => void; | ||
setState?: (key: string, state: any, storage: Storage) => void; | ||
filter?: (mutation: MutationPayload) => boolean; | ||
arrayMerger?: (state: any, saved: any) => any; | ||
rehydrated?: (store: typeof Store) => void; | ||
arrayMerger?: (state: any[], saved: any[]) => any; | ||
rehydrated?: (store: Store<State>) => void; | ||
fetchBeforeUse?: boolean; | ||
@@ -23,3 +23,3 @@ overwrite?: boolean; | ||
} | ||
export default function (options?: Options): (store: any) => void; | ||
export default function <State>(options?: Options<State>): (store: Store<State>) => void; | ||
export {}; |
{ | ||
"name": "vuex-persistedstate", | ||
"description": "Persist and rehydrate your Vuex state between page reloads.", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "author": "Robin van der Vleuten <robin@webstronauts.co> (robinvdvleuten.nl)", |
@@ -7,3 +7,3 @@ # vuex-persistedstate | ||
[![Build Status](https://img.shields.io/travis/robinvdvleuten/vuex-persistedstate.svg)](https://travis-ci.org/robinvdvleuten/vuex-persistedstate) | ||
[![Build Status](https://img.shields.io/github/workflow/status/robinvdvleuten/vuex-persistedstate/test.svg)](https://github.com/robinvdvleuten/vuex-persistedstate/actions?query=workflow%3Atest) | ||
[![NPM version](https://img.shields.io/npm/v/vuex-persistedstate.svg)](https://www.npmjs.com/package/vuex-persistedstate) | ||
@@ -17,2 +17,6 @@ [![NPM downloads](https://img.shields.io/npm/dm/vuex-persistedstate.svg)](https://www.npmjs.com/package/vuex-persistedstate) | ||
<a href="https://webstronauts.com/"> | ||
<img src="https://webstronauts.com/badges/sponsored-by-webstronauts.svg" alt="Sponsored by The Webstronauts" width="200" height="65"> | ||
</a> | ||
## Requirements | ||
@@ -60,5 +64,32 @@ | ||
## Usage with Vuex modules | ||
New plugin instances can be created in separate files, but must be imported and added to plugins object in the main Vuex file. | ||
```js | ||
/* module.js */ | ||
export const dataStore = { | ||
state: { | ||
data: [] | ||
} | ||
} | ||
/* store.js */ | ||
import { dataStore } from './module' | ||
const dataState = createPersistedState({ | ||
paths: ['data'] | ||
}) | ||
export new Vuex.Store({ | ||
modules: { | ||
dataStore | ||
}, | ||
plugins: [dataState] | ||
}) | ||
``` | ||
### Nuxt.js | ||
It is possible to use vuex-persistedstate with Nuxt.js. Due to the order code is loaded in, vuex-persistedstate must be included as a NuxtJS plugin: | ||
It is possible to use vuex-persistedstate with Nuxt.js. It must be included as a NuxtJS plugin: | ||
@@ -79,9 +110,7 @@ ```javascript | ||
export default ({store}) => { | ||
window.onNuxtReady(() => { | ||
createPersistedState({ | ||
key: 'yourkey', | ||
paths: [...] | ||
... | ||
})(store) | ||
}) | ||
createPersistedState({ | ||
key: 'yourkey', | ||
paths: [...] | ||
... | ||
})(store) | ||
} | ||
@@ -102,3 +131,3 @@ ``` | ||
- `storage <Object>`: Instead for (or in combination with) `getState` and `setState`. Defaults to localStorage. | ||
- `storage <Object>`: Instead of (or in combination with) `getState` and `setState`. Defaults to localStorage. | ||
- `getState <Function>`: A function that will be called to rehydrate a previously persisted state. Defaults to using `storage`. | ||
@@ -180,2 +209,6 @@ - `setState <Function>`: A function that will be called to persist the given state. Defaults to using `storage`. | ||
## Changelog | ||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. | ||
## Contributors ✨ | ||
@@ -209,3 +242,2 @@ | ||
<td align="center"><a href="https://github.com/NLNicoo"><img src="https://avatars2.githubusercontent.com/u/6526666?v=4" width="100px;" alt=""/><br /><sub><b>Nico</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=NLNicoo" title="Code">💻</a> <a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=NLNicoo" title="Tests">⚠️</a></td> | ||
<td align="center"><a href="https://graficos.net"><img src="https://avatars2.githubusercontent.com/u/6775220?v=4" width="100px;" alt=""/><br /><sub><b>Paul Melero</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=gangsthub" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://www.qkdreyer.dev"><img src="https://avatars3.githubusercontent.com/u/717869?v=4" width="100px;" alt=""/><br /><sub><b>Quentin Dreyer</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=qkdreyer" title="Code">💻</a></td> | ||
@@ -216,9 +248,16 @@ <td align="center"><a href="http://raphaelsaunier.com"><img src="https://avatars2.githubusercontent.com/u/170256?v=4" width="100px;" alt=""/><br /><sub><b>Raphael Saunier</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=raphaelsaunier" title="Code">💻</a></td> | ||
<td align="center"><a href="https://atinux.com"><img src="https://avatars2.githubusercontent.com/u/904724?v=4" width="100px;" alt=""/><br /><sub><b>Sébastien Chopin</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=Atinux" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://github.com/zgayjjf"><img src="https://avatars1.githubusercontent.com/u/24718872?v=4" width="100px;" alt=""/><br /><sub><b>jeffjing</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=zgayjjf" title="Code">💻</a></td> | ||
</tr> | ||
<tr> | ||
<td align="center"><a href="https://github.com/zgayjjf"><img src="https://avatars1.githubusercontent.com/u/24718872?v=4" width="100px;" alt=""/><br /><sub><b>jeffjing</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=zgayjjf" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/macarthuror"><img src="https://avatars0.githubusercontent.com/u/24395219?v=4" width="100px;" alt=""/><br /><sub><b>macarthuror</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=macarthuror" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://github.com/gangsthub"><img src="https://avatars2.githubusercontent.com/u/6775220?s=460&v=4" width="100px;" alt=""/><br /><sub><b>Paul Melero</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=gangsthub" title="Documentation">📖</a> <a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=gangsthub" title="Code">💻</a> <a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=gangsthub" title="Tests">⚠️</a></td> | ||
<td align="center"><a href="https://github.com/WTDuck"><img src="https://avatars0.githubusercontent.com/u/16686729?v=4" width="100px;" alt=""/><br /><sub><b>Guillaume da Silva</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=WTDuck" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/SanterreJo"><img src="https://avatars2.githubusercontent.com/u/6465769?v=4" width="100px;" alt=""/><br /><sub><b>Jonathan Santerre</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=SanterreJo" title="Code">💻</a></td> | ||
<td align="center"><a href="https://www.linkedin.com/in/fabiofdsantos/"><img src="https://avatars3.githubusercontent.com/u/8303937?v=4" width="100px;" alt=""/><br /><sub><b>Fábio Santos</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=fabiofdsantos" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://github.com/robertgr991"><img src="https://avatars0.githubusercontent.com/u/36689800?v=4" width="100px;" alt=""/><br /><sub><b>robertgr991</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=robertgr991" title="Code">💻</a></td> | ||
<td align="center"><a href="https://github.com/YuraKolesnikov"><img src="https://avatars3.githubusercontent.com/u/28485518?v=4" width="100px;" alt=""/><br /><sub><b>JurijsKolesnikovs</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=YuraKolesnikov" title="Documentation">📖</a></td> | ||
</tr> | ||
<tr> | ||
<td align="center"><a href="https://davidsbond.github.io"><img src="https://avatars3.githubusercontent.com/u/6227720?v=4" width="100px;" alt=""/><br /><sub><b>David Bond</b></sub></a><br /><a href="https://github.com/robinvdvleuten/vuex-persistedstate/commits?author=davidsbond" title="Documentation">📖</a></td> | ||
</tr> | ||
</table> | ||
@@ -225,0 +264,0 @@ |
@@ -11,15 +11,15 @@ import { Store, MutationPayload } from "vuex"; | ||
interface Options { | ||
interface Options<State> { | ||
key?: string; | ||
paths?: string[]; | ||
reducer?: (state: any, paths: string[]) => object; | ||
reducer?: (state: State, paths: string[]) => object; | ||
subscriber?: ( | ||
store: typeof Store | ||
) => (handler: (mutation: any, state: any) => void) => void; | ||
store: Store<State> | ||
) => (handler: (mutation: any, state: State) => void) => void; | ||
storage?: Storage; | ||
getState?: (key: string, storage: Storage) => any; | ||
setState?: (key: string, state: typeof Store, storage: Storage) => void; | ||
setState?: (key: string, state: any, storage: Storage) => void; | ||
filter?: (mutation: MutationPayload) => boolean; | ||
arrayMerger?: (state: any, saved: any) => any; | ||
rehydrated?: (store: typeof Store) => void; | ||
arrayMerger?: (state: any[], saved: any[]) => any; | ||
rehydrated?: (store: Store<State>) => void; | ||
fetchBeforeUse?: boolean; | ||
@@ -30,3 +30,5 @@ overwrite?: boolean; | ||
export default function (options?: Options) { | ||
export default function <State>( | ||
options?: Options<State> | ||
): (store: Store<State>) => void { | ||
options = options || {}; | ||
@@ -88,3 +90,3 @@ | ||
return function (store) { | ||
return function (store: Store<State>) { | ||
if (!options.fetchBeforeUse) { | ||
@@ -91,0 +93,0 @@ savedState = fetchSavedState(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71212
12
157
267