UNPKG

@vueblocks/vue-use-vuex

Version:
60 lines (57 loc) 2.97 kB
import { Store } from 'vuex'; /** * Reduce the code which written in Vue.js for getting the state. * @param {String} [namespace] - Module's namespace * @param {Object|Array} states # Object's item can be a function which accept state and getters for param, you can do something for state and getters in it. * @param {Object} */ declare const useState: (store: Store<any>, namespace: string, states: Array<string> | object) => object; /** * Reduce the code which written in Vue.js for committing the mutation * @param {String} [namespace] - Module's namespace * @param {Object|Array} mutations # Object's item can be a function which accept `commit` function as the first param, it can accept anthor params. You can commit mutation and do any other things in this function. specially, You need to pass anthor params from the mapped function. * @return {Object} */ declare const useMutations: (store: any, namespace: string, mutations: Array<string> | object) => object; /** * Reduce the code which written in Vue.js for getting the getters * @param {String} [namespace] - Module's namespace * @param {Object|Array} getters * @return {Object} */ declare const useGetters: (store: Store<any>, namespace: string, getters: Array<string> | object) => object; /** * Reduce the code which written in Vue.js for dispatch the action * @param {String} [namespace] - Module's namespace * @param {Object|Array} actions # Object's item can be a function which accept `dispatch` function as the first param, it can accept anthor params. You can dispatch action and do any other things in this function. specially, You need to pass anthor params from the mapped function. * @return {Object} */ declare const useActions: (store: any, namespace: string, actions: Array<string> | object) => object; /** * Rebinding namespace param for mapXXX function in special scoped, and return them by simple object * @param {String} namespace * @return {Object} */ declare const createNamespacedHelpers: (store: Store<any>, namespace: string) => { useState: (...args: any[]) => any; useGetters: (...args: any[]) => any; useMutations: (...args: any[]) => any; useActions: (...args: any[]) => any; }; /** * Get $store from current instance * @return {Store} instance.$store */ declare const useStore: () => Store<any>; /** * Use Vuex with composition api easily. Both support Vue2.x / Vue3.x * @param {String} namespace * @param {Store} store vm.$store */ declare function useVuex(namespace?: string, store?: Store<any>): { useState: (namespace?: any, map?: object | string[] | undefined) => object; useGetters: (namespace?: any, map?: object | string[] | undefined) => object; useMutations: (namespace?: any, map?: object | string[] | undefined) => object; useActions: (namespace?: any, map?: object | string[] | undefined) => object; }; export { createNamespacedHelpers, useActions, useGetters, useMutations, useState, useStore, useVuex };