This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+27
View File
@@ -0,0 +1,27 @@
import Vue from 'vue';
import { mapState, mapGetters, mapActions, mapMutations } from 'vuex';
export declare type VuexDecorator = <V extends Vue>(proto: V, key: string) => void;
export declare type StateTransformer = (state: any, getters: any) => any;
export declare type MapHelper = typeof mapState | typeof mapGetters | typeof mapActions | typeof mapMutations;
export interface BindingOptions {
namespace?: string;
}
export interface BindingHelper {
<V extends Vue>(proto: V, key: string): void;
(type: string, options?: BindingOptions): VuexDecorator;
}
export interface StateBindingHelper extends BindingHelper {
(type: StateTransformer, options?: BindingOptions): VuexDecorator;
}
export interface BindingHelpers {
State: StateBindingHelper;
Getter: BindingHelper;
Mutation: BindingHelper;
Action: BindingHelper;
}
export declare const State: StateBindingHelper;
export declare const Getter: BindingHelper;
export declare const Action: BindingHelper;
export declare const Mutation: BindingHelper;
export declare function namespace(namespace: string): BindingHelpers;
export declare function namespace<T extends BindingHelper>(namespace: string, helper: T): T;
+75
View File
@@ -0,0 +1,75 @@
import { createDecorator } from 'vue-class-component';
import { mapState, mapGetters, mapActions, mapMutations } from 'vuex';
export var State = createBindingHelper('computed', mapState);
export var Getter = createBindingHelper('computed', mapGetters);
export var Action = createBindingHelper('methods', mapActions);
export var Mutation = createBindingHelper('methods', mapMutations);
export function namespace(namespace, helper) {
function createNamespacedHelper(helper) {
function namespacedHelper(a, b) {
if (typeof b === 'string') {
var key = b;
var proto = a;
return helper(key, { namespace: namespace })(proto, key);
}
var type = a;
var options = merge(b || {}, { namespace: namespace });
return helper(type, options);
}
return namespacedHelper;
}
if (helper) {
console.warn('[vuex-class] passing the 2nd argument to `namespace` function is deprecated. pass only namespace string instead.');
return createNamespacedHelper(helper);
}
return {
State: createNamespacedHelper(State),
Getter: createNamespacedHelper(Getter),
Mutation: createNamespacedHelper(Mutation),
Action: createNamespacedHelper(Action)
};
}
function createBindingHelper(bindTo, mapFn) {
function makeDecorator(map, namespace) {
return createDecorator(function (componentOptions, key) {
if (!componentOptions[bindTo]) {
componentOptions[bindTo] = {};
}
var mapObject = (_a = {}, _a[key] = map, _a);
componentOptions[bindTo][key] = namespace !== undefined
? mapFn(namespace, mapObject)[key]
: mapFn(mapObject)[key];
var _a;
});
}
function helper(a, b) {
if (typeof b === 'string') {
var key = b;
var proto = a;
return makeDecorator(key, undefined)(proto, key);
}
var namespace = extractNamespace(b);
var type = a;
return makeDecorator(type, namespace);
}
return helper;
}
function extractNamespace(options) {
var n = options && options.namespace;
if (typeof n !== 'string') {
return undefined;
}
if (n[n.length - 1] !== '/') {
return n + '/';
}
return n;
}
function merge(a, b) {
var res = {};
[a, b].forEach(function (obj) {
Object.keys(obj).forEach(function (key) {
res[key] = obj[key];
});
});
return res;
}
+1
View File
@@ -0,0 +1 @@
export { State, Getter, Action, Mutation, namespace } from './bindings';
+1
View File
@@ -0,0 +1 @@
export { State, Getter, Action, Mutation, namespace } from './bindings';