-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
50 lines (32 loc) · 1.07 KB
/
test.js
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
var OO = require("./index");
let oo = new OO();
let oo2 = new OO();
const test1 = (type, data, ...params) => {
console.log("Event type is ", type, ", data is ", data);
if (params) {
let l = params.length;
if (l > 0) {
for (let i = 0; i < l-1; i++) {
console.log("Parameter #", i, ' is ', params[i]);
}
console.log("Sender's signature is: ", params[l-1].signature, '\n');
}
}
};
oo.signature = "Test OO";
oo2.signature = "Secondary Test OO";
oo.on("event1", test1 );
oo2.on("event11", test1 );
oo.once("event2", (type, data) => {
console.log("Event type 2 is logged with data ", data, '\n');
});
console.log(">>=== OK now, let's test the first object observers");
oo.emit("event1", "test", 1, 2);
oo.emit("event1", { text: "test", data: 0 } );
oo.emit("event2", "test");
oo.emit("event2", { text: "test", data: 0 } );
oo.off("event2");
oo.off("event1", test1);
oo.emit("event1", "test");
console.log("==== Now, test the secondary object's observers");
oo2.emit("event11", "some data");