@eleven-am/pondsocket 0.1.9 → 0.1.11
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/package.json +1 -1
- package/pondBase/baseClass.js +32 -51
- package/pondBase/baseClass.test.js +34 -34
- package/pondBase/pondBase.js +34 -95
- package/pondBase/pondBase.test.js +39 -67
- package/pondBase/pubSub.d.ts +8 -9
- package/pondBase/pubSub.js +65 -121
- package/pondBase/pubSub.test.js +119 -110
- package/pondBase/simpleBase.js +92 -166
- package/pondBase/simpleBase.test.js +66 -124
- package/pondClient/channel.d.ts +14 -3
- package/pondClient/channel.js +71 -46
- package/pondClient/socket.js +35 -38
- package/pondSocket/channel.js +123 -176
- package/pondSocket/channel.test.js +78 -89
- package/pondSocket/channelMiddleWare.js +16 -43
- package/pondSocket/endpoint.js +93 -188
- package/pondSocket/endpoint.test.js +447 -632
- package/pondSocket/pondChannel.js +81 -142
- package/pondSocket/pondChannel.test.js +40 -40
- package/pondSocket/pondResponse.js +52 -87
- package/pondSocket/pondSocket.js +35 -55
- package/pondSocket/server.test.js +88 -142
- package/pondSocket/socketMiddleWare.js +14 -16
package/pondBase/pubSub.js
CHANGED
|
@@ -1,135 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __values = (this && this.__values) || function(o) {
|
|
18
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
-
if (m) return m.call(o);
|
|
20
|
-
if (o && typeof o.length === "number") return {
|
|
21
|
-
next: function () {
|
|
22
|
-
if (o && i >= o.length) o = void 0;
|
|
23
|
-
return { value: o && o[i++], done: !o };
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
3
|
exports.EventPubSub = exports.Subject = exports.Broadcast = void 0;
|
|
30
|
-
|
|
31
|
-
|
|
4
|
+
class Broadcast {
|
|
5
|
+
constructor() {
|
|
32
6
|
this._subscribers = new Set();
|
|
33
7
|
}
|
|
34
8
|
/**
|
|
35
9
|
* @desc Subscribe to the broadcast
|
|
36
10
|
* @param handler - The handler to call when the broadcast is published
|
|
37
11
|
*/
|
|
38
|
-
|
|
39
|
-
var _this = this;
|
|
12
|
+
subscribe(handler) {
|
|
40
13
|
this._subscribers.add(handler);
|
|
41
14
|
return {
|
|
42
15
|
/**
|
|
43
16
|
* @desc Unsubscribe from the broadcast
|
|
44
17
|
*/
|
|
45
|
-
unsubscribe:
|
|
46
|
-
|
|
18
|
+
unsubscribe: () => {
|
|
19
|
+
this._subscribers.delete(handler);
|
|
47
20
|
}
|
|
48
21
|
};
|
|
49
|
-
}
|
|
50
|
-
Object.defineProperty(Broadcast.prototype, "subscriberCount", {
|
|
51
|
-
/**
|
|
52
|
-
* @desc Gets the number of subscribers
|
|
53
|
-
*/
|
|
54
|
-
get: function () {
|
|
55
|
-
return this._subscribers.size;
|
|
56
|
-
},
|
|
57
|
-
enumerable: false,
|
|
58
|
-
configurable: true
|
|
59
|
-
});
|
|
22
|
+
}
|
|
60
23
|
/**
|
|
61
24
|
* @desc Publish to the broadcast
|
|
62
25
|
* @param data - The data to publish
|
|
63
26
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
for (var _b = __values(this._subscribers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
69
|
-
var subscriber = _c.value;
|
|
27
|
+
publish(data) {
|
|
28
|
+
let result;
|
|
29
|
+
for (const subscriber of this._subscribers) {
|
|
30
|
+
try {
|
|
70
31
|
result = subscriber(data);
|
|
71
32
|
if (result)
|
|
72
33
|
break;
|
|
73
34
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
finally {
|
|
77
|
-
try {
|
|
78
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw e;
|
|
79
37
|
}
|
|
80
|
-
finally { if (e_1) throw e_1.error; }
|
|
81
38
|
}
|
|
82
39
|
return result;
|
|
83
|
-
}
|
|
40
|
+
}
|
|
84
41
|
/**
|
|
85
42
|
* @dec clears all subscribers
|
|
86
43
|
*/
|
|
87
|
-
|
|
44
|
+
clear() {
|
|
88
45
|
this._subscribers.clear();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
}());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
92
48
|
exports.Broadcast = Broadcast;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
49
|
+
class Subject extends Broadcast {
|
|
50
|
+
constructor(value) {
|
|
51
|
+
super();
|
|
52
|
+
this._value = value;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @desc Get the current value of the subject
|
|
56
|
+
*/
|
|
57
|
+
get value() {
|
|
58
|
+
return this._value;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @desc Get the list of observers
|
|
62
|
+
* @returns The list of observers
|
|
63
|
+
*/
|
|
64
|
+
get observers() {
|
|
65
|
+
return this._subscribers;
|
|
99
66
|
}
|
|
100
|
-
Object.defineProperty(Subject.prototype, "value", {
|
|
101
|
-
/**
|
|
102
|
-
* @desc Get the current value of the subject
|
|
103
|
-
*/
|
|
104
|
-
get: function () {
|
|
105
|
-
return this._value;
|
|
106
|
-
},
|
|
107
|
-
enumerable: false,
|
|
108
|
-
configurable: true
|
|
109
|
-
});
|
|
110
67
|
/**
|
|
111
68
|
* @desc Subscribe to the subject
|
|
112
|
-
* @param handler - The handler to call when the subject is published
|
|
113
69
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return
|
|
117
|
-
}
|
|
70
|
+
subscribe(handler) {
|
|
71
|
+
handler(this._value);
|
|
72
|
+
return super.subscribe(handler);
|
|
73
|
+
}
|
|
118
74
|
/**
|
|
119
75
|
* @desc Publish to the subject
|
|
120
|
-
* @param data - The data to publish
|
|
121
76
|
*/
|
|
122
|
-
|
|
77
|
+
publish(data) {
|
|
123
78
|
if (this._value !== data) {
|
|
124
79
|
this._value = data;
|
|
125
|
-
return
|
|
80
|
+
return super.publish(data);
|
|
126
81
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
}(Broadcast));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
130
84
|
exports.Subject = Subject;
|
|
131
|
-
|
|
132
|
-
|
|
85
|
+
class EventPubSub {
|
|
86
|
+
constructor() {
|
|
133
87
|
this._subscribers = new Set();
|
|
134
88
|
}
|
|
135
89
|
/**
|
|
@@ -137,51 +91,42 @@ var EventPubSub = /** @class */ (function () {
|
|
|
137
91
|
* @param event - The event to subscribe to
|
|
138
92
|
* @param handler - The handler to call when the event subject is published
|
|
139
93
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var subscriber = function (eventData) {
|
|
94
|
+
subscribe(event, handler) {
|
|
95
|
+
const subscriber = (eventData) => {
|
|
143
96
|
if (eventData.type === event)
|
|
144
97
|
return handler(eventData.data);
|
|
145
|
-
return undefined;
|
|
146
98
|
};
|
|
147
99
|
this._subscribers.add(subscriber);
|
|
148
100
|
return {
|
|
149
101
|
/**
|
|
150
102
|
* @desc Unsubscribe from the event subject
|
|
151
103
|
*/
|
|
152
|
-
unsubscribe:
|
|
153
|
-
|
|
104
|
+
unsubscribe: () => {
|
|
105
|
+
this._subscribers.delete(subscriber);
|
|
154
106
|
}
|
|
155
107
|
};
|
|
156
|
-
}
|
|
108
|
+
}
|
|
157
109
|
/**
|
|
158
110
|
* @desc Publish to the event subject
|
|
159
111
|
* @param event - The event to publish
|
|
160
112
|
* @param data - The data to publish
|
|
161
113
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
try {
|
|
165
|
-
for (var _b = __values(this._subscribers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
166
|
-
var subscriber = _c.value;
|
|
167
|
-
void subscriber({ type: event, data: data });
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
171
|
-
finally {
|
|
114
|
+
publish(event, data) {
|
|
115
|
+
for (const subscriber of this._subscribers) {
|
|
172
116
|
try {
|
|
173
|
-
|
|
117
|
+
subscriber({ type: event, data });
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
throw e;
|
|
174
121
|
}
|
|
175
|
-
finally { if (e_2) throw e_2.error; }
|
|
176
122
|
}
|
|
177
|
-
}
|
|
123
|
+
}
|
|
178
124
|
/**
|
|
179
125
|
* @desc Subscribe to all events
|
|
180
126
|
* @param handler - The handler to call when the event subject is published
|
|
181
127
|
*/
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
var subscriber = function (eventData) {
|
|
128
|
+
subscribeAll(handler) {
|
|
129
|
+
const subscriber = (eventData) => {
|
|
185
130
|
return handler(eventData.data);
|
|
186
131
|
};
|
|
187
132
|
this._subscribers.add(subscriber);
|
|
@@ -189,26 +134,25 @@ var EventPubSub = /** @class */ (function () {
|
|
|
189
134
|
/**
|
|
190
135
|
* @desc Unsubscribe from the event subject
|
|
191
136
|
*/
|
|
192
|
-
unsubscribe:
|
|
193
|
-
|
|
137
|
+
unsubscribe: () => {
|
|
138
|
+
this._subscribers.delete(subscriber);
|
|
194
139
|
}
|
|
195
140
|
};
|
|
196
|
-
}
|
|
141
|
+
}
|
|
197
142
|
/**
|
|
198
143
|
* @desc Complete the event subject
|
|
199
144
|
*/
|
|
200
|
-
|
|
145
|
+
complete() {
|
|
201
146
|
this._subscribers.clear();
|
|
202
147
|
if (this._onComplete)
|
|
203
148
|
this._onComplete();
|
|
204
|
-
}
|
|
149
|
+
}
|
|
205
150
|
/**
|
|
206
151
|
* @desc Subscribe to the event subject completion
|
|
207
152
|
* @param handler - The handler to call when the event subject is completed
|
|
208
153
|
*/
|
|
209
|
-
|
|
154
|
+
onComplete(handler) {
|
|
210
155
|
this._onComplete = handler;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
}());
|
|
156
|
+
}
|
|
157
|
+
}
|
|
214
158
|
exports.EventPubSub = EventPubSub;
|