UNPKG

vuex-xhr-state

Version:

Use Vuex to manage the state of you're ajax calls.

77 lines (76 loc) 2.65 kB
import { createDecorator } from 'vue-class-component'; import { Action } from 'vuex-class'; import { ACTION } from './keys'; // Actions // export function vxsAction (method: string, call: iVuexXhr) { // return Action(method, {namespace: call.namespace}) // } export function vxsActionFetch(call) { return Action(ACTION.FETCH, { namespace: call.namespace }); } export function vxsActionSend(call) { return Action(ACTION.SEND, { namespace: call.namespace }); } export function vxsActionForcefetch(call) { return Action(ACTION.FORCE_FETCH, { namespace: call.namespace }); } export function vxsActionReset(call) { return Action(ACTION.RESET, { namespace: call.namespace }); } export function vxsActionInvalidate(call) { return Action(ACTION.INVALIDATE, { namespace: call.namespace }); } export function vxsActionInvalidateAll(call) { return Action(ACTION.INVALIDATE_ALL, { namespace: call.namespace }); } // Getters export function vxsDataGetter(call) { return createDecorator(function (componentOptions, key) { if (!componentOptions.methods) { componentOptions.methods = {}; } componentOptions.methods[key] = function (payload) { return call.data(this.$store.getters, payload); }; }); } export function vxsPendingGetter(call) { return createDecorator(function (componentOptions, key) { if (!componentOptions.methods) { componentOptions.methods = {}; } componentOptions.methods[key] = function (payload) { return call.pending(this.$store.getters, payload); }; }); } export function vxsHasErrorGetter(call) { return createDecorator(function (componentOptions, key) { if (!componentOptions.methods) { componentOptions.methods = {}; } componentOptions.methods[key] = function (payload) { return call.hasError(this.$store.getters, payload); }; }); } export function vxsFetchedGetter(call) { return createDecorator(function (componentOptions, key) { if (!componentOptions.methods) { componentOptions.methods = {}; } componentOptions.methods[key] = function (payload) { return call.fetched(this.$store.getters, payload); }; }); } export function vxsResponseGetter(call) { return createDecorator(function (componentOptions, key) { if (!componentOptions.methods) { componentOptions.methods = {}; } componentOptions.methods[key] = function (payload) { return call.response(this.$store.getters, payload); }; }); }