Created
May 17, 2022 12:40
-
-
Save AmShaegar13/862d72d768d371f90bc411300df546d4 to your computer and use it in GitHub Desktop.
Pinia plain JavaScript inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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