@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.
@@ -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
- var Broadcast = /** @class */ (function () {
31
- function Broadcast() {
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
- Broadcast.prototype.subscribe = function (handler) {
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: function () {
46
- _this._subscribers.delete(handler);
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
- Broadcast.prototype.publish = function (data) {
65
- var e_1, _a;
66
- var result;
67
- try {
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
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
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
- Broadcast.prototype.clear = function () {
44
+ clear() {
88
45
  this._subscribers.clear();
89
- };
90
- return Broadcast;
91
- }());
46
+ }
47
+ }
92
48
  exports.Broadcast = Broadcast;
93
- var Subject = /** @class */ (function (_super) {
94
- __extends(Subject, _super);
95
- function Subject(value) {
96
- var _this = _super.call(this) || this;
97
- _this._value = value;
98
- return _this;
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
- Subject.prototype.subscribe = function (handler) {
115
- void handler(this._value);
116
- return _super.prototype.subscribe.call(this, handler);
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
- Subject.prototype.publish = function (data) {
77
+ publish(data) {
123
78
  if (this._value !== data) {
124
79
  this._value = data;
125
- return _super.prototype.publish.call(this, data);
80
+ return super.publish(data);
126
81
  }
127
- };
128
- return Subject;
129
- }(Broadcast));
82
+ }
83
+ }
130
84
  exports.Subject = Subject;
131
- var EventPubSub = /** @class */ (function () {
132
- function EventPubSub() {
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
- EventPubSub.prototype.subscribe = function (event, handler) {
141
- var _this = this;
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: function () {
153
- _this._subscribers.delete(subscriber);
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
- EventPubSub.prototype.publish = function (event, data) {
163
- var e_2, _a;
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
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
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
- EventPubSub.prototype.subscribeAll = function (handler) {
183
- var _this = this;
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: function () {
193
- _this._subscribers.delete(subscriber);
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
- EventPubSub.prototype.complete = function () {
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
- EventPubSub.prototype.onComplete = function (handler) {
154
+ onComplete(handler) {
210
155
  this._onComplete = handler;
211
- };
212
- return EventPubSub;
213
- }());
156
+ }
157
+ }
214
158
  exports.EventPubSub = EventPubSub;