This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.html
90 lines (68 loc) · 2.51 KB
/
test.html
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
83
84
85
86
87
88
89
90
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Testing JZ Publish/Subscribe</title>
</head>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript" src="src/jquery.pubsub.js"></script>
<script type="text/javascript">
var obj = {
data: true,
func: function (t,d) {
console.log("this.data = " +this.data + "; t = " +t+ "; d = " +d+ ";");
},
unfunc: function (t,d) {
console.log("this.data = " +this.data + "; t = " +t+ "; d = " +d+ "; UNSUB");
$.unsubscribe(t, obj.unfunc);
}
}
$.subscribe('test', obj.func);
$.subscribe('test', obj.func, obj);
$.publish('test','data1');
console.info("-----publish finished-----: t=test; d=data1; 1=undefined, 2=true");
$.unsubscribe('test', obj.func);
$.publish('test', 'data2');
console.info("-----publish finished-----: t=test; d=data2; 1=true");
$.unsubscribe('test', obj.func, obj);
$.publish('test', 'data3');
console.info("-----publish finished-----: t=test; d=data3; 0");
var h1 = $.subscribe('test', obj.func);
$.publish('test', 'data4');
console.info("-----publish finished-----: t=test; d=data4; 1=undefined");
var h2 = $.subscribe('test', obj.func, obj);
$.publish('test', 'data5');
console.info("-----publish finished-----: t=test; d=data5; 1=undefined, 2=true");
$.unsubscribe(h1);
$.publish('test', 'data6');
console.info("-----publish finished-----: t=test; d=data6; 1=true");
$.unsubscribe(h2);
$.publish('test', 'data7');
console.info("-----publish finished-----: t=test; d=data7; 0");
$.subscribe('test', obj.func);
$.subscribe('test', obj.func);
$.subscribe('test', obj.func);
$.subscribe('test', obj.func);
$.subscribe('test', obj.func);
$.subscribe('test', obj.func, obj);
$.subscribe('test', obj.func, obj);
$.subscribe('test', obj.func, obj);
$.subscribe('test', obj.func, obj);
$.subscribe('test', obj.func, obj);
$.publish('test', 'data8');
console.info("-----publish finished-----: t=test; d=data8; 1-5=undefined, 6-10=true");
$.unsubscribe('test');
$.publish('test', 'data9');
console.info("-----publish finished-----: t=test; d=data9; 0");
$.subscribe('test', obj.unfunc);
$.subscribe('test', obj.unfunc);
$.subscribe('test', obj.unfunc);
$.subscribe('test', obj.unfunc);
$.publish('test', 'data10');
console.info("-----publish finished-----: t=test; d=data10; 4=undefined; UNSUB");
$.publish('test', 'data11');
console.info("-----publish finished-----: t=test; d=data11; 0");
</script>
</body>
</html>