-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimal.ts
79 lines (65 loc) · 1.58 KB
/
minimal.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
import type { CustomEvent } from "@dimkl/events";
import { dispatch, on } from "@dimkl/events";
//
// Definition example
//
class Person {
public firstName: string;
public lastName: string;
constructor(firstName: string, lastName: string) {
this.firstName = firstName;
this.lastName = lastName;
}
@dispatch()
getFullName() {
return `${this.firstName} ${this.lastName}`;
}
@dispatch()
sayAloha() {
console.log("said: ", this.aloha());
}
@dispatch()
async asyncGetFullName() {
return `${this.firstName} ${this.lastName}`;
}
aloha() {
return "Aloha to all";
}
@dispatch()
async alohaAsync() {
return "Aloha to all";
}
}
class ExplicitPersonHandler {
@on({ eventName: "person:getFullName" })
static handleGetFullName(event: CustomEvent) {
console.log(
"ExplicitPersonHandler: event listener for getFullName: ",
event.data
);
}
@on({ eventName: "person:sayAloha" })
static handleSayAloha(event: CustomEvent) {
console.log(
"ExplicitPersonHandler: event listener for sayAloha: ",
event.data
);
}
@on({ eventName: "person:asyncGetFullName" })
static handleAsyncGetFullName(event: CustomEvent) {
console.log(
"ExplicitPersonHandler: event listener for asyncGetFullName: ",
event.data
);
}
}
console.log(`
---- Minimal example ----
`);
const p = new Person("Fistname", "Lastname");
p.asyncGetFullName();
console.log("log getFullName(): ", p.getFullName());
p.sayAloha();
p.firstName = "Fistname2";
console.log("log getFullName(): ", p.getFullName());
p.alohaAsync();