entangld 2.2.0 → 2.3.1
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/.eslintrc.json +29 -0
- package/README.md +481 -414
- package/generate_docs.js +3 -3
- package/index.js +8 -1357
- package/lib/Datastore.js +855 -0
- package/lib/Message.js +148 -0
- package/lib/Subscription.js +216 -0
- package/lib/error.js +43 -0
- package/lib/utils.js +265 -0
- package/package.json +8 -9
- package/tags +244 -0
- package/test/circular.js +3 -7
- package/test/events.js +1 -1
- package/test/sockets.js +19 -19
- package/test/subscriptions.js +51 -51
- package/test/tests.js +382 -383
- package/test/single.js +0 -48
package/test/subscriptions.js
CHANGED
|
@@ -19,9 +19,9 @@ describe("Subscription", function() {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
afterEach(function() {
|
|
22
|
-
delete s;
|
|
23
|
-
delete a;
|
|
24
|
-
delete b;
|
|
22
|
+
delete s; // eslint-disable-line no-delete-var
|
|
23
|
+
delete a; // eslint-disable-line no-delete-var
|
|
24
|
+
delete b; // eslint-disable-line no-delete-var
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it("Should only trigger subscriptions on an exact match", function(done) {
|
|
@@ -35,14 +35,14 @@ describe("Subscription", function() {
|
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
it("Should emit on recieved subscriptions (locally)", function(done) {
|
|
38
|
-
s.on("subscription", ( path
|
|
38
|
+
s.on("subscription", ( path ) => {
|
|
39
39
|
if ( path === "test" ) { done(); return; }
|
|
40
40
|
assert.fail("Subcription yield path " + path);
|
|
41
41
|
});
|
|
42
42
|
s.subscribe('test', () => {});
|
|
43
43
|
});
|
|
44
44
|
it("Should emit on recieved unsubscriptions (locally)", function(done) {
|
|
45
|
-
s.on("unsubscription", ( path
|
|
45
|
+
s.on("unsubscription", ( path ) => {
|
|
46
46
|
if ( path === "test" ) { done(); return; }
|
|
47
47
|
assert.fail("Subcription yield path " + path);
|
|
48
48
|
});
|
|
@@ -51,14 +51,14 @@ describe("Subscription", function() {
|
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
it("Should emit on recieved subscriptions (remote)", function(done) {
|
|
54
|
-
a.on("subscription", ( path
|
|
54
|
+
a.on("subscription", ( path ) => {
|
|
55
55
|
if ( path === "some_data" ) { done(); return; }
|
|
56
56
|
assert.fail("Subcription yield path " + path);
|
|
57
57
|
});
|
|
58
58
|
s.subscribe('path1.A.some_data', () => {});
|
|
59
59
|
});
|
|
60
60
|
it("Should emit on recieved unsubscriptions (remote)", function(done) {
|
|
61
|
-
a.on("unsubscription", ( path
|
|
61
|
+
a.on("unsubscription", ( path ) => {
|
|
62
62
|
if ( path === "some_data" ) { done(); return; }
|
|
63
63
|
assert.fail("Subcription yield path " + path);
|
|
64
64
|
});
|
|
@@ -67,7 +67,7 @@ describe("Subscription", function() {
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
it("Shouldn't emit on sent subscriptions (remote)", function(done) {
|
|
70
|
-
s.on("subscription", (
|
|
70
|
+
s.on("subscription", () => {
|
|
71
71
|
assert.fail("this shouldn't run");
|
|
72
72
|
});
|
|
73
73
|
s.subscribe('path1.A.path3.B.something', () => {});
|
|
@@ -75,7 +75,7 @@ describe("Subscription", function() {
|
|
|
75
75
|
done();
|
|
76
76
|
});
|
|
77
77
|
it("Shouldn't emit on sent unsubscriptions (remote)", function(done) {
|
|
78
|
-
s.on("unsubscription", (
|
|
78
|
+
s.on("unsubscription", () => {
|
|
79
79
|
assert.fail("this shouldn't run");
|
|
80
80
|
});
|
|
81
81
|
s.subscribe('path1.A.path3.B.something', () => {});
|
|
@@ -84,7 +84,7 @@ describe("Subscription", function() {
|
|
|
84
84
|
done();
|
|
85
85
|
});
|
|
86
86
|
it("Shouldn't emit on passthrough subscriptions (remote)", function(done) {
|
|
87
|
-
a.on("subscription", (
|
|
87
|
+
a.on("subscription", () => {
|
|
88
88
|
assert.fail("this shouldn't run");
|
|
89
89
|
});
|
|
90
90
|
s.subscribe('path1.A.path3.B.something', () => {});
|
|
@@ -92,7 +92,7 @@ describe("Subscription", function() {
|
|
|
92
92
|
done();
|
|
93
93
|
});
|
|
94
94
|
it("Shouldn't emit on passthrough unsubscriptions (remote)", function(done) {
|
|
95
|
-
a.on("unsubscription", (
|
|
95
|
+
a.on("unsubscription", () => {
|
|
96
96
|
assert.fail("this shouldn't run");
|
|
97
97
|
});
|
|
98
98
|
s.subscribe('path1.A.path3.B.something', () => {});
|
|
@@ -103,7 +103,7 @@ describe("Subscription", function() {
|
|
|
103
103
|
|
|
104
104
|
it("Emit on each subscription", function(done) {
|
|
105
105
|
let count = 0;
|
|
106
|
-
b.on("subscription", ( path
|
|
106
|
+
b.on("subscription", ( path ) => {
|
|
107
107
|
count += 1;
|
|
108
108
|
assert.strictEqual(path, "something");
|
|
109
109
|
});
|
|
@@ -118,8 +118,8 @@ describe("Subscription", function() {
|
|
|
118
118
|
|
|
119
119
|
var count = 0;
|
|
120
120
|
// Create two subscriptions
|
|
121
|
-
s.subscribe("some_data", () => {count += 1});
|
|
122
|
-
s.subscribe("some_data", () => {count += 1});
|
|
121
|
+
s.subscribe("some_data", () => {count += 1;});
|
|
122
|
+
s.subscribe("some_data", () => {count += 1;});
|
|
123
123
|
|
|
124
124
|
s.set('some_data', 0.0);
|
|
125
125
|
|
|
@@ -130,7 +130,7 @@ describe("Subscription", function() {
|
|
|
130
130
|
|
|
131
131
|
it("Can (not) throttle subscription messages (locally)", (done) => {
|
|
132
132
|
var count = 0;
|
|
133
|
-
s.subscribe("some_data", (
|
|
133
|
+
s.subscribe("some_data", () => { count += 1; }, 1);
|
|
134
134
|
for ( let i = 0; i < 10; i ++ ) {
|
|
135
135
|
s.set("some_data", 1);
|
|
136
136
|
}
|
|
@@ -140,7 +140,7 @@ describe("Subscription", function() {
|
|
|
140
140
|
|
|
141
141
|
it("Can throttle subscription messages (locally)", (done) => {
|
|
142
142
|
var count = 0;
|
|
143
|
-
s.subscribe("some_data", (
|
|
143
|
+
s.subscribe("some_data", () => { count += 1; }, 2);
|
|
144
144
|
for ( let i = 0; i < 10; i ++ ) {
|
|
145
145
|
s.set("some_data", 1);
|
|
146
146
|
}
|
|
@@ -150,7 +150,7 @@ describe("Subscription", function() {
|
|
|
150
150
|
|
|
151
151
|
it("Can throttle subscription messages (remote)", (done) => {
|
|
152
152
|
var count = 0;
|
|
153
|
-
s.subscribe("path1.A.path3.B.some_data", (
|
|
153
|
+
s.subscribe("path1.A.path3.B.some_data", () => { count += 1; }, 2);
|
|
154
154
|
for ( let i = 0; i < 10; i ++ ) {
|
|
155
155
|
b.set("some_data", 1);
|
|
156
156
|
}
|
|
@@ -162,8 +162,8 @@ describe("Subscription", function() {
|
|
|
162
162
|
|
|
163
163
|
var count = 0;
|
|
164
164
|
// Create two subscriptions
|
|
165
|
-
s.subscribe("some_data", () => {count += 1});
|
|
166
|
-
s.subscribe("some_data", () => {count += 1});
|
|
165
|
+
s.subscribe("some_data", () => {count += 1;});
|
|
166
|
+
s.subscribe("some_data", () => {count += 1;});
|
|
167
167
|
|
|
168
168
|
s.set('some_data', 0.0);
|
|
169
169
|
|
|
@@ -176,8 +176,8 @@ describe("Subscription", function() {
|
|
|
176
176
|
|
|
177
177
|
var count = 0;
|
|
178
178
|
// Create two subscriptions
|
|
179
|
-
s.subscribe("path1.A.some_data", () => {count += 1});
|
|
180
|
-
s.subscribe("path1.A.some_data", () => {count += 1});
|
|
179
|
+
s.subscribe("path1.A.some_data", () => {count += 1;});
|
|
180
|
+
s.subscribe("path1.A.some_data", () => {count += 1;});
|
|
181
181
|
|
|
182
182
|
a.set('some_data', 0.0);
|
|
183
183
|
|
|
@@ -190,26 +190,26 @@ describe("Subscription", function() {
|
|
|
190
190
|
s.subscribe("num1", () => {});
|
|
191
191
|
s.subscribe("path1.A.num1", () => {});
|
|
192
192
|
s.subscribe("path1.A.path3.B.num1", () => {});
|
|
193
|
-
assert.strictEqual(s.subscriptions.length, 3)
|
|
194
|
-
assert.strictEqual(a.subscriptions.length, 2)
|
|
195
|
-
assert.strictEqual(b.subscriptions.length, 1)
|
|
193
|
+
assert.strictEqual(s.subscriptions.length, 3);
|
|
194
|
+
assert.strictEqual(a.subscriptions.length, 2);
|
|
195
|
+
assert.strictEqual(b.subscriptions.length, 1);
|
|
196
196
|
done();
|
|
197
|
-
});
|
|
197
|
+
});
|
|
198
198
|
|
|
199
199
|
it("Unsubscribing paths removes all paths", (done)=>{
|
|
200
200
|
|
|
201
201
|
var count = 0;
|
|
202
202
|
// Create two subscriptions
|
|
203
|
-
s.subscribe("some_data", () => {count += 1});
|
|
204
|
-
s.subscribe("some_data", () => {count += 1});
|
|
203
|
+
s.subscribe("some_data", () => {count += 1;});
|
|
204
|
+
s.subscribe("some_data", () => {count += 1;});
|
|
205
205
|
|
|
206
|
-
s.unsubscribe("some_data")
|
|
206
|
+
s.unsubscribe("some_data");
|
|
207
207
|
|
|
208
208
|
s.set('some_data', 0.0);
|
|
209
209
|
|
|
210
210
|
assert.strictEqual(count, 0);
|
|
211
211
|
|
|
212
|
-
done()
|
|
212
|
+
done();
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
|
|
@@ -217,10 +217,10 @@ describe("Subscription", function() {
|
|
|
217
217
|
|
|
218
218
|
var count = 0;
|
|
219
219
|
// Create two subscriptions
|
|
220
|
-
let uuid1 = s.subscribe("some_data", () => {count += 1});
|
|
221
|
-
let uuid2 = s.subscribe("some_data", () => {count += 1});
|
|
220
|
+
let uuid1 = s.subscribe("some_data", () => {count += 1;});
|
|
221
|
+
let uuid2 = s.subscribe("some_data", () => {count += 1;});
|
|
222
222
|
|
|
223
|
-
s.unsubscribe(uuid1)
|
|
223
|
+
s.unsubscribe(uuid1);
|
|
224
224
|
|
|
225
225
|
s.set('some_data', 0.0);
|
|
226
226
|
|
|
@@ -228,28 +228,28 @@ describe("Subscription", function() {
|
|
|
228
228
|
assert.strictEqual(s._subscriptions.length, 1);
|
|
229
229
|
assert.strictEqual(s._subscriptions[0].uuid, uuid2);
|
|
230
230
|
|
|
231
|
-
done()
|
|
231
|
+
done();
|
|
232
232
|
});
|
|
233
233
|
|
|
234
234
|
it("Pairs of remote stores can subscribe to the same data", (done)=>{
|
|
235
235
|
|
|
236
236
|
var count = 0;
|
|
237
|
-
s.subscribe("path2.B.some_data", () => {count += 1});
|
|
238
|
-
a.subscribe("path3.B.some_data", () => {count += 1})
|
|
237
|
+
s.subscribe("path2.B.some_data", () => {count += 1;});
|
|
238
|
+
a.subscribe("path3.B.some_data", () => {count += 1;});
|
|
239
239
|
|
|
240
240
|
b.set("some_data",0.0);
|
|
241
241
|
|
|
242
242
|
assert.strictEqual(count, 2);
|
|
243
243
|
|
|
244
|
-
done()
|
|
244
|
+
done();
|
|
245
245
|
});
|
|
246
246
|
|
|
247
247
|
|
|
248
248
|
it("Pairs of remote stores don't unsubscribe each other", (done)=>{
|
|
249
249
|
|
|
250
250
|
var count = 0;
|
|
251
|
-
|
|
252
|
-
let uuid2 = a.subscribe("path3.B.some_data", () => {count += 1})
|
|
251
|
+
s.subscribe("path2.B.some_data", () => {count += 1;});
|
|
252
|
+
let uuid2 = a.subscribe("path3.B.some_data", () => {count += 1;});
|
|
253
253
|
|
|
254
254
|
s.unsubscribe("path2.B.some_data");
|
|
255
255
|
|
|
@@ -259,7 +259,7 @@ describe("Subscription", function() {
|
|
|
259
259
|
assert.strictEqual(b._subscriptions.length, 1);
|
|
260
260
|
assert.strictEqual(b._subscriptions[0].uuid, uuid2);
|
|
261
261
|
|
|
262
|
-
done()
|
|
262
|
+
done();
|
|
263
263
|
});
|
|
264
264
|
|
|
265
265
|
it("Orphaned remote subscriptions are successfully cleaned up", (done) => {
|
|
@@ -270,11 +270,11 @@ describe("Subscription", function() {
|
|
|
270
270
|
|
|
271
271
|
s.transmit((msg, store)=> {
|
|
272
272
|
if (msg.type==="unsubscribe") number_of_cancels_sent += 1;
|
|
273
|
-
store.receive(msg, s)
|
|
273
|
+
store.receive(msg, s);
|
|
274
274
|
});
|
|
275
275
|
a.transmit((msg, store)=> {
|
|
276
276
|
if (msg.type==="event") number_of_events += 1;
|
|
277
|
-
store.receive(msg, a)
|
|
277
|
+
store.receive(msg, a);
|
|
278
278
|
});
|
|
279
279
|
|
|
280
280
|
|
|
@@ -283,32 +283,32 @@ describe("Subscription", function() {
|
|
|
283
283
|
// orphan the pass through subscription object in A
|
|
284
284
|
s._subscriptions = [];
|
|
285
285
|
|
|
286
|
-
a.set("some_data",0.0)
|
|
286
|
+
a.set("some_data",0.0);
|
|
287
287
|
|
|
288
288
|
// The cancel message was sent from S to A
|
|
289
|
-
assert.strictEqual(number_of_cancels_sent,1)
|
|
290
|
-
assert.strictEqual(number_of_events,1)
|
|
289
|
+
assert.strictEqual(number_of_cancels_sent,1);
|
|
290
|
+
assert.strictEqual(number_of_events,1);
|
|
291
291
|
|
|
292
|
-
a.set("some_data",0.0)
|
|
292
|
+
a.set("some_data",0.0);
|
|
293
293
|
|
|
294
294
|
// A didn't sent the next next event
|
|
295
|
-
assert.strictEqual(number_of_events,1)
|
|
295
|
+
assert.strictEqual(number_of_events,1);
|
|
296
296
|
|
|
297
297
|
done();
|
|
298
|
-
})
|
|
298
|
+
});
|
|
299
299
|
|
|
300
300
|
it("Local sets only triggers a single subscribed callback when multiple subscriptions co-exist", (done)=>{
|
|
301
301
|
|
|
302
302
|
// Subscribe once to a local endpoint
|
|
303
303
|
var sub_1_triggers = 0;
|
|
304
|
-
s.subscribe("some_data",(
|
|
304
|
+
s.subscribe("some_data",()=>{
|
|
305
305
|
sub_1_triggers += 1;
|
|
306
306
|
assert.strictEqual(sub_1_triggers, 1);
|
|
307
307
|
});
|
|
308
308
|
|
|
309
309
|
// Subscribe again to the same local endpoint
|
|
310
310
|
var sub_2_triggers = 0;
|
|
311
|
-
s.subscribe("some_data",(
|
|
311
|
+
s.subscribe("some_data",()=>{
|
|
312
312
|
sub_2_triggers += 1;
|
|
313
313
|
assert.strictEqual(sub_2_triggers, 1);
|
|
314
314
|
});
|
|
@@ -322,14 +322,14 @@ describe("Subscription", function() {
|
|
|
322
322
|
|
|
323
323
|
// Subscribe once to a remote endpoint
|
|
324
324
|
var sub_1_triggers = 0;
|
|
325
|
-
s.subscribe("path1.A.some_data",(
|
|
325
|
+
s.subscribe("path1.A.some_data",()=>{
|
|
326
326
|
sub_1_triggers += 1;
|
|
327
327
|
assert.strictEqual(sub_1_triggers, 1);
|
|
328
328
|
});
|
|
329
329
|
|
|
330
330
|
// Subscribe again to the same remote endpoint
|
|
331
331
|
var sub_2_triggers = 0;
|
|
332
|
-
s.subscribe("path1.A.some_data",(
|
|
332
|
+
s.subscribe("path1.A.some_data",()=>{
|
|
333
333
|
sub_2_triggers += 1;
|
|
334
334
|
assert.strictEqual(sub_2_triggers, 1);
|
|
335
335
|
});
|