1.0.3 • Published 1 year ago

@drupalhunter/unstorage-pinia-plugin v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

unstorage-pinia-plugin

Persist and hydrate your pinia state using unstorage!

Install

# npm
npm install unstorage @drupalhunter/unstorage-pinia-plugin

## Usage
You can use any available [unstorage driver](https://github.com/unjs/unstorage#drivers). Drivers can be set either globally or per store. Locally defined driver overrides global definition.

Global driver:
```ts
// pinia.ts
import { createPinia } from 'pinia';
import { createUnstoragePlugin } from '@drupalhunter/unstorage-pinia-plugin';
import localStorageDriver from 'unstorage/drivers/localstorage';

const pinia = createPinia();

pinia.use(createUnstoragePlugin({
  // unstorage plugin options
}));

export default pinia;

Per store driver:

// pinia.ts
import { createPinia } from 'pinia';
import { createUnstoragePlugin } from '@drupalhunter/unstorage-pinia-plugin';

const pinia = createPinia();

pinia.use(createUnstoragePlugin());

export default pinia;
// store.ts
import { computed, ref } from 'vue';
import { defineStore } from 'pinia';
import { defineStoreStorage } from '@drupalhunter/unstorage-pinia-plugin';
import localStorageDriver from 'unstorage/drivers/localstorage';

export const useStore = defineStore(
  'store',
  () => {
    // setup and return your state, getters and actions
  },
  {
    unstorage: {
      // unstorage store options
    }
  }
});

If you prefer the option way:

import { defineUnstore } from '@drupalhunter/unstorage-pinia-plugin';
import localStorageDriver from 'unstorage/drivers/localstorage';

export const useStore = defineUnstore(
  'store',
  {
    // define your state, getters and actions
  },
  {
    // unstorage store options
  }
);

Configuration

Plugin options

  • driver: Driver : Default unstorage driver (see list).

Store options

  • driver: Driver : Driver for the store (see list).

  • filter?: Array<string> : State keys you actually want to persist. All keys are pushed by default.

1.0.3

1 year ago

1.0.2

1 year ago