Skip to content

Instantly share code, notes, and snippets.

@AmShaegar13
Created May 17, 2022 12:40
Show Gist options
  • Save AmShaegar13/862d72d768d371f90bc411300df546d4 to your computer and use it in GitHub Desktop.
Save AmShaegar13/862d72d768d371f90bc411300df546d4 to your computer and use it in GitHub Desktop.
Pinia plain JavaScript inheritance
function baseCounterStore(options) {
const baseState = {
counter: 0
}
const newState = options.state
options.state = () => {
return {
...baseState,
...newState()
}
}
options.getters = {
...options.getters,
doubleCounter: (state) => {
return state.counter * 2
}
}
return options
}
export const useShoppingCartStore = defineStore(
baseCounterStore({
id: 'shopping-cart',
state: () => ({}),
getters: {}
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment