1.0.1 • Published 5 months ago

pinia-shared-state v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

pinia-shared-state

npm (tag) npm bundle size NPM

Sync your Pinia state across browser tabs.

Requirements

  • vue ^3.5.11

Install

npm install pinia-shared-state

Usage

import { PiniaSharedState } from 'pinia-shared-state'

// Pass the plugin to your application's pinia plugin
pinia.use(
  PiniaSharedState({
    // Enables the plugin for all stores. Defaults to true.
    enable: true,
    // If set to true this tab tries to immediately recover the shared state from another tab. Defaults to true.
    initialize: false,
    // Enforce a type. One of native, idb, localstorage or node. Defaults to native.
    type: 'localstorage',
  }),
)
const useStore = defineStore({
  id: 'counter',
  state: () => ({
    count: 0,
    foo: 'bar',
  }),
  share: {
    // An array of fields that the plugin will ignore.
    omit: ['foo'],
    // Override global config for this store.
    enable: true,
    initialize: true,
  },
})

Vanilla usage:

import { share } from 'pinia-shared-state'
import { onMounted, onUnmounted } from 'vue'
import useStore from './store'

const counterStore = useStore()

onMounted(() => {
  const { unshare } = share('counter', counterStore, { initialize: true })

  onUnmounted(() => {
    // Call `unshare` method to close the channel
    unshare()
  })
})

License

MIT

1.0.1

5 months ago

1.0.0

5 months ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.3.0

2 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.8

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.4

3 years ago

0.2.2

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.3

4 years ago

0.1.0

4 years ago

0.1.1

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.1

4 years ago