@routier/core 0.8.0 → 0.8.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/dist/index.cjs +33 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -33
- package/dist/index.js.map +1 -1
- package/dist/schema/index.cjs +33 -33
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.js +33 -33
- package/dist/schema/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -13264,7 +13264,6 @@ const getChannelRegistry = (schemaId, scope)=>{
|
|
|
13264
13264
|
registry[key] = channel;
|
|
13265
13265
|
return channel;
|
|
13266
13266
|
};
|
|
13267
|
-
// Must have a sender and receiver. Sender cannot listen for it's own message
|
|
13268
13267
|
class SchemaChannel {
|
|
13269
13268
|
sender;
|
|
13270
13269
|
receiver;
|
|
@@ -13273,8 +13272,8 @@ class SchemaChannel {
|
|
|
13273
13272
|
// hence a count rather than a boolean.
|
|
13274
13273
|
subscribers = 0;
|
|
13275
13274
|
constructor(channelKey){
|
|
13276
|
-
this.sender = new SchemaChannelSender(channelKey);
|
|
13277
13275
|
this.receiver = new SchemaChannelReceiver(channelKey);
|
|
13276
|
+
this.sender = new SchemaChannelSender(channelKey, this.receiver);
|
|
13278
13277
|
}
|
|
13279
13278
|
/**
|
|
13280
13279
|
* How many callbacks in THIS process are waiting on the channel.
|
|
@@ -13298,51 +13297,50 @@ class SchemaChannel {
|
|
|
13298
13297
|
this.receiver.close();
|
|
13299
13298
|
}
|
|
13300
13299
|
}
|
|
13301
|
-
|
|
13302
|
-
|
|
13303
|
-
|
|
13304
|
-
|
|
13305
|
-
|
|
13306
|
-
* does not call `destroyAsync()` runs to the end of its code and then hangs forever with two
|
|
13307
|
-
* live MessagePorts per collection — including the example in the README.
|
|
13308
|
-
*
|
|
13309
|
-
* `unref` is Node-only; the browser's BroadcastChannel has no such method and needs none.
|
|
13310
|
-
* A channel that is unreferenced still sends and receives normally. It only stops being a
|
|
13311
|
-
* reason for the process to stay alive, which is the correct default for a library: a program
|
|
13312
|
-
* with no work left should exit.
|
|
13313
|
-
*/ const unreference = (channel)=>{
|
|
13300
|
+
const openBroadcastChannel = (channelKey)=>{
|
|
13301
|
+
if (typeof BroadcastChannel !== "function") {
|
|
13302
|
+
return null;
|
|
13303
|
+
}
|
|
13304
|
+
const channel = new BroadcastChannel(`__routier-schema-subscription-channel:${channelKey}`);
|
|
13314
13305
|
const maybeUnref = channel.unref;
|
|
13315
|
-
if (typeof maybeUnref ===
|
|
13306
|
+
if (typeof maybeUnref === "function") {
|
|
13316
13307
|
maybeUnref.call(channel);
|
|
13317
13308
|
}
|
|
13309
|
+
return channel;
|
|
13318
13310
|
};
|
|
13319
13311
|
class SchemaChannelSender {
|
|
13320
13312
|
broadcastChannel;
|
|
13321
|
-
|
|
13322
|
-
|
|
13323
|
-
|
|
13313
|
+
localReceiver;
|
|
13314
|
+
constructor(channelKey, localReceiver){
|
|
13315
|
+
this.broadcastChannel = openBroadcastChannel(channelKey);
|
|
13316
|
+
this.localReceiver = localReceiver;
|
|
13324
13317
|
}
|
|
13325
13318
|
send(changes) {
|
|
13326
|
-
this.broadcastChannel
|
|
13319
|
+
if (this.broadcastChannel != null) {
|
|
13320
|
+
this.broadcastChannel.postMessage(changes);
|
|
13321
|
+
return;
|
|
13322
|
+
}
|
|
13323
|
+
const copy = structuredClone(changes);
|
|
13324
|
+
setTimeout(()=>this.localReceiver.dispatch(copy), 0);
|
|
13327
13325
|
}
|
|
13328
13326
|
close() {
|
|
13329
|
-
this.broadcastChannel
|
|
13327
|
+
this.broadcastChannel?.close();
|
|
13330
13328
|
}
|
|
13331
13329
|
}
|
|
13332
13330
|
class SchemaChannelReceiver {
|
|
13333
13331
|
broadcastChannel;
|
|
13334
13332
|
subscriptions = [];
|
|
13335
13333
|
constructor(channelKey){
|
|
13336
|
-
this.broadcastChannel =
|
|
13337
|
-
|
|
13338
|
-
|
|
13339
|
-
|
|
13340
|
-
|
|
13341
|
-
|
|
13342
|
-
|
|
13343
|
-
|
|
13344
|
-
|
|
13345
|
-
}
|
|
13334
|
+
this.broadcastChannel = openBroadcastChannel(channelKey);
|
|
13335
|
+
if (this.broadcastChannel != null) {
|
|
13336
|
+
this.broadcastChannel.onmessage = (e)=>this.dispatch(e.data);
|
|
13337
|
+
}
|
|
13338
|
+
}
|
|
13339
|
+
dispatch(changes) {
|
|
13340
|
+
const subscriptions = this.subscriptions;
|
|
13341
|
+
for(let i = 0, length = subscriptions.length; i < length; i++){
|
|
13342
|
+
subscriptions[i].action(changes);
|
|
13343
|
+
}
|
|
13346
13344
|
}
|
|
13347
13345
|
get listenerCount() {
|
|
13348
13346
|
return this.subscriptions.length;
|
|
@@ -13355,8 +13353,10 @@ class SchemaChannelReceiver {
|
|
|
13355
13353
|
}
|
|
13356
13354
|
close() {
|
|
13357
13355
|
this.subscriptions = [];
|
|
13358
|
-
this.broadcastChannel
|
|
13359
|
-
|
|
13356
|
+
if (this.broadcastChannel != null) {
|
|
13357
|
+
this.broadcastChannel.onmessage = null;
|
|
13358
|
+
this.broadcastChannel.close();
|
|
13359
|
+
}
|
|
13360
13360
|
}
|
|
13361
13361
|
}
|
|
13362
13362
|
class SubscriptionListener {
|