-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunc.ts
82 lines (71 loc) · 2.18 KB
/
Func.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import Command from "./Command";
import { EventDispatcher } from "../events/EventDispatcher";
import Event from "../events/Event";
export default class Func extends Command {
constructor(func: Function, args: any[] = [], eventDispatcher: EventDispatcher = null, eventName: string = null) {
super();
this.func = func;
this.args = args;
this.eventDispatcher = eventDispatcher;
this.eventName = eventName;
}
protected implExecuteFunction(command: Command): void {
if (this.eventDispatcher && this.eventName) {
this.eventDispatcher.addEventListener(this.eventName, this.completeHandler);
this.func.call(this, this.args);
} else {
this.func.call(this, this.args);
this.notifyComplete();
}
}
protected implInterruptFunction(command: Command): void {
if (this.eventDispatcher && this.eventName) {
this.eventDispatcher.removeEventListener(this.eventName, this.completeHandler);
}
}
protected implDestroyFunction(command: Command): void {
if (this.eventDispatcher && this.eventName) {
this.eventDispatcher.removeEventListener(this.eventName, this.completeHandler);
}
this.eventDispatcher = null;
this.eventName = null;
this.func = null;
this.args = null;
}
private completeHandler = (event: Event): void => {
this.notifyComplete();
};
// --------------------------------------------------
//
// MEMBER
//
// --------------------------------------------------
private func: Function;
public getFunction(): Function {
return this.func;
}
public setFunction(func: Function): void {
this.func = func;
}
private args: any[];
public getArguments(): any[] {
return this.args;
}
public setArguments(args: any[]): void {
this.args = args;
}
private eventDispatcher: EventDispatcher;
public getEventDispatcher(): EventDispatcher {
return this.eventDispatcher;
}
public setEventDispatcher(eventDispatcher: EventDispatcher): void {
this.eventDispatcher = eventDispatcher;
}
private eventName: string;
public getEventName(): string {
return this.eventName;
}
public setEventName(eventName: string): void {
this.eventName = eventName;
}
}