Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Vue from 'vue'
- import Vuex from 'vuex'
- Vue.use(Vuex)
- /**
- * @interface StoreState
- */
- export interface StoreState {
- [key: string]: any
- }
- /**
- * @interface StoreOptions
- */
- export interface StoreOptions {
- state: StoreState,
- mutations: any
- }
- /**
- * @interface StoreObservable
- */
- export interface StoreObservable {
- state: StoreState,
- commit: Function
- }
- /**
- * Helper to create dynamic stores
- * Useful to reduce boilerplate.. simple and functional
- * Besides the store is standalone and works fine in a lot of places
- * @param {StoreOptions} options
- * @returns {StoreObservable}
- */
- export default (options: StoreOptions): StoreObservable => {
- const { state, mutations } = options
- return {
- state: Vue.observable(state),
- commit (mutation: any, ...args: any) {
- mutations[mutation](state, ...args)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement