Skip to content

Plugin Ref Unwrapping #497

May 15, 2021 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

You need to do

import { ref, computed, set } from '@vue/composition-api'
pinia.use(({ store }) => {
  // this is because plugins can be instantiated multiple times as mentioned in the docs intruduction
  if (!Object.hasOwnProperty(store.$state, 'status') {
    const idleRef = ref('Idle')
    set(store.$state, 'status', idleRef)
    set(store, 'status', idleRef)
    const loadingRef =  computed(() => store.status === 'Loading')
    set(store.$state, 'isLoading', loadingRef)
    set(store., 'isLoading', loadingRef)
  }
})

because the properties are not initially declared on the store. I thought I added a note about mutating the state and adding properties (in plugins) to follow the same rea…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@posva
Comment options

@posva
Comment options

@duckies
Comment options

@posva
Comment options

@posva
Comment options

posva Jun 1, 2021
Maintainer

Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants