larasopp 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Core.js +1 -0
- package/lib/Subscribe.d.ts +2 -0
- package/lib/Subscribe.js +12 -0
- package/package.json +1 -1
- package/src/Core.ts +1 -0
- package/src/Subscribe.ts +8 -0
package/lib/Core.js
CHANGED
package/lib/Subscribe.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface ISubscribe {
|
|
|
11
11
|
}
|
|
12
12
|
declare class Subscribe {
|
|
13
13
|
private events;
|
|
14
|
+
private currentEvents;
|
|
14
15
|
private hasChannel;
|
|
15
16
|
private pushChannel;
|
|
16
17
|
private removeChannel;
|
|
@@ -21,6 +22,7 @@ declare class Subscribe {
|
|
|
21
22
|
get channel(): string;
|
|
22
23
|
private init;
|
|
23
24
|
bind<T>(event: string, callback: (data: T) => void): TBind;
|
|
25
|
+
private clearEvents;
|
|
24
26
|
remove(): void;
|
|
25
27
|
addListener(event: TListenerEvents, callback: TListenerCallback): Event | undefined;
|
|
26
28
|
}
|
package/lib/Subscribe.js
CHANGED
|
@@ -8,6 +8,12 @@ class Subscribe {
|
|
|
8
8
|
writable: true,
|
|
9
9
|
value: void 0
|
|
10
10
|
});
|
|
11
|
+
Object.defineProperty(this, "currentEvents", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
11
17
|
Object.defineProperty(this, "hasChannel", {
|
|
12
18
|
enumerable: true,
|
|
13
19
|
configurable: true,
|
|
@@ -45,6 +51,7 @@ class Subscribe {
|
|
|
45
51
|
value: void 0
|
|
46
52
|
});
|
|
47
53
|
this.events = events;
|
|
54
|
+
this.currentEvents = [];
|
|
48
55
|
this.hasChannel = hasChannel;
|
|
49
56
|
this.pushChannel = pushChannel;
|
|
50
57
|
this.removeChannel = removeChannel;
|
|
@@ -74,13 +81,18 @@ class Subscribe {
|
|
|
74
81
|
}
|
|
75
82
|
bind(event, callback) {
|
|
76
83
|
const Event = this.events.addListener(this.channel + ':' + event, callback);
|
|
84
|
+
this.currentEvents.push(Event);
|
|
77
85
|
return {
|
|
78
86
|
remove: () => {
|
|
79
87
|
Event.remove();
|
|
80
88
|
}
|
|
81
89
|
};
|
|
82
90
|
}
|
|
91
|
+
clearEvents() {
|
|
92
|
+
this.currentEvents.forEach((event) => event.remove());
|
|
93
|
+
}
|
|
83
94
|
remove() {
|
|
95
|
+
this.clearEvents();
|
|
84
96
|
this.removeChannel(this.channel);
|
|
85
97
|
if (this.hasChannel(this.channel))
|
|
86
98
|
return;
|
package/package.json
CHANGED
package/src/Core.ts
CHANGED
package/src/Subscribe.ts
CHANGED
|
@@ -23,6 +23,7 @@ interface ISubscribe {
|
|
|
23
23
|
|
|
24
24
|
class Subscribe {
|
|
25
25
|
private events: Events;
|
|
26
|
+
private currentEvents: Event[];
|
|
26
27
|
private hasChannel: (channel: string) => boolean;
|
|
27
28
|
private pushChannel: (channel: string) => void;
|
|
28
29
|
private removeChannel: (channel: string) => void;
|
|
@@ -32,6 +33,7 @@ class Subscribe {
|
|
|
32
33
|
|
|
33
34
|
constructor({events, hasChannel, pushChannel, removeChannel, status, channel, send}: ISubscribe) {
|
|
34
35
|
this.events = events;
|
|
36
|
+
this.currentEvents = [];
|
|
35
37
|
this.hasChannel = hasChannel;
|
|
36
38
|
this.pushChannel = pushChannel;
|
|
37
39
|
this.removeChannel = removeChannel;
|
|
@@ -65,6 +67,7 @@ class Subscribe {
|
|
|
65
67
|
|
|
66
68
|
public bind<T>(event: string, callback: (data: T) => void): TBind {
|
|
67
69
|
const Event = this.events.addListener(this.channel + ':' + event, callback);
|
|
70
|
+
this.currentEvents.push(Event);
|
|
68
71
|
return {
|
|
69
72
|
remove: () => {
|
|
70
73
|
Event.remove();
|
|
@@ -72,7 +75,12 @@ class Subscribe {
|
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
private clearEvents(): void {
|
|
79
|
+
this.currentEvents.forEach((event) => event.remove());
|
|
80
|
+
}
|
|
81
|
+
|
|
75
82
|
public remove(): void {
|
|
83
|
+
this.clearEvents();
|
|
76
84
|
this.removeChannel(this.channel);
|
|
77
85
|
if (this.hasChannel(this.channel)) return;
|
|
78
86
|
this.send({
|