UNPKG

vue-rest-hooks

Version:

typescript restfull-api reactive @vue/composition-api

30 lines (29 loc) 1.25 kB
import { normalizeNamespace, isValidMap, normalizeMap, getModuleByNamespace } from "../utils"; export var mapMutationsConvert = function (store) { return normalizeNamespace(function (store, namespace, mutations) { var res = {}; if (process.env.NODE_ENV !== "production" && !isValidMap(mutations)) { console.error("[vuex] mapMutations: mapper parameter must be either an Array or an Object"); } normalizeMap(mutations).forEach(function (_a) { var key = _a.key, val = _a.val; res[key] = function mappedMutation() { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } // Get the commit method from store var commit = store.commit; if (namespace) { var module_1 = getModuleByNamespace(store, "mapMutations", namespace); if (!module_1) { return; } commit = module_1.context.commit; } return commit.apply(store, [val].concat(args)); }; }); return res; }, store); };