Plugin Ref Unwrapping #497
-
Hello, I'm currently trying to implement a plugin similar to the debounce example that adds a My issue is if I add a I have tried a few different ways but I have reactivity through something like this, just no unwrapping. pinia.use(({ store }) => ({
status: ref("Idle"),
isLoading: computed(() => store.status.value === "Loading")
})); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
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 reactivity rules as Vue (for Vue 2) like Vuex shows at https://vuex.vuejs.org/guide/mutations.html#mutations-follow-vue-s-reactivity-rules Note that if they are meant to be serialized or used during SSR, they need to be added **both on Besides this, there is a bugfix that hasn't been released yet that makes the whole thing work but I tested with a locally installed version and it works after removing all the |
Beta Was this translation helpful? Give feedback.
You need to do
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…