-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall.ts
50 lines (47 loc) · 1.28 KB
/
all.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { attrs, SAttributeType } from './attribute';
import { styles, SStyleType } from './style';
import { classes, SClassType } from './class';
import { SDragEventType } from './drag';
import { onkey, SKeyboardEventType } from './keyboard';
import { onmouse, SMouseEventType } from './mouse';
import { ondrag } from './drag';
import S from 's-js';
export const addEvents = (node: Node, arg: any) => {
for (const key in arg) {
const val: any = (arg as any)[key];
node.addEventListener(key, val, false);
S.cleanup(function() {
node.removeEventListener(key, val);
});
}
};
export type ISurplusMixins = {
onmouse?: SMouseEventType;
onkey?: SKeyboardEventType;
ondrag?: SDragEventType;
classes?: SClassType | SClassType[];
styles?: SStyleType | SStyleType[];
attrs?: SAttributeType | SAttributeType;
};
const mixinMap: any = {
onmouse: onmouse,
onkey: onkey,
ondrag: ondrag,
classes: classes,
styles: styles,
attrs: attrs
};
export function mixins(...args: ISurplusMixins[]) {
return function mixins(node: any) {
if (args) {
args.forEach((arg: any) => {
for (const key in arg) {
mixinMap[key].apply(
null,
arg[key] instanceof Array ? arg[key] : [arg[key]]
)(node);
}
});
}
};
}