-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvuex.ts
27 lines (25 loc) · 823 Bytes
/
vuex.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { getDeepValue } from './utils/tools';
export function Getter(getter: string | Function) {
return function (target: any, key: string) {
//create the temp getters holder if non existane
if (!target.$$getters) target.$$getters = {};
if (typeof getter === 'function') {
target.$$getters[key] = getter;
} else {
target.$$getters[key] = (state: Object) => {
return getDeepValue(state, getter);
};
}
//remove it from the instance so it is not added to data
delete target[key];
};
}
export function Action(action: Function) {
return function (target: any, key: string) {
//create the temp actions holder if non existane
if (!target.$$actions) target.$$actions = {};
target.$$actions[key] = action;
//remove it from the instance so it is not added to data
delete target[key];
};
}