-
Notifications
You must be signed in to change notification settings - Fork 1
/
prop.ts
32 lines (27 loc) · 871 Bytes
/
prop.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
28
29
30
31
32
import { Constructor } from './utils/utilities';
export interface PropOption {
type?: Constructor | Constructor[] | null;
required?: boolean;
default?: any;
twoWay?: boolean;
validator?(value: any): boolean;
coerce?(value: any): any;
}
export default function Prop(options?: PropOption) {
return function (target: any, key: string) {
//create the temp props holder if non existane
if (!target.$$props) target.$$props = {};
if (!options) options = null;
if (!options && target[key]) {
options = {};
options['default'] = target[key];
} else if (options && target[key]) {
options['default'] = target[key];
}
target.$$props[key] = options;
//remove it from the instance so it is not added to data or methods
if (!target.$$methodsToRemove) target.$$methodsToRemove = [];
target.$$methodsToRemove.push(key);
delete target[key];
};
}