@routier/core 0.8.0 → 0.8.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/dist/index.cjs +78 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +82 -36
- package/dist/index.js.map +1 -1
- package/dist/results/index.cjs +40 -0
- package/dist/results/index.cjs.map +1 -1
- package/dist/results/index.d.ts +1 -0
- package/dist/results/index.js +44 -1
- package/dist/results/index.js.map +1 -1
- package/dist/results/liveQuery.d.ts +26 -0
- 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/schema/index.js
CHANGED
|
@@ -4638,7 +4638,6 @@ const getChannelRegistry = (schemaId, scope)=>{
|
|
|
4638
4638
|
registry[key] = channel;
|
|
4639
4639
|
return channel;
|
|
4640
4640
|
};
|
|
4641
|
-
// Must have a sender and receiver. Sender cannot listen for it's own message
|
|
4642
4641
|
class SchemaChannel {
|
|
4643
4642
|
sender;
|
|
4644
4643
|
receiver;
|
|
@@ -4647,8 +4646,8 @@ class SchemaChannel {
|
|
|
4647
4646
|
// hence a count rather than a boolean.
|
|
4648
4647
|
subscribers = 0;
|
|
4649
4648
|
constructor(channelKey){
|
|
4650
|
-
this.sender = new SchemaChannelSender(channelKey);
|
|
4651
4649
|
this.receiver = new SchemaChannelReceiver(channelKey);
|
|
4650
|
+
this.sender = new SchemaChannelSender(channelKey, this.receiver);
|
|
4652
4651
|
}
|
|
4653
4652
|
/**
|
|
4654
4653
|
* How many callbacks in THIS process are waiting on the channel.
|
|
@@ -4672,51 +4671,50 @@ class SchemaChannel {
|
|
|
4672
4671
|
this.receiver.close();
|
|
4673
4672
|
}
|
|
4674
4673
|
}
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
* does not call `destroyAsync()` runs to the end of its code and then hangs forever with two
|
|
4681
|
-
* live MessagePorts per collection — including the example in the README.
|
|
4682
|
-
*
|
|
4683
|
-
* `unref` is Node-only; the browser's BroadcastChannel has no such method and needs none.
|
|
4684
|
-
* A channel that is unreferenced still sends and receives normally. It only stops being a
|
|
4685
|
-
* reason for the process to stay alive, which is the correct default for a library: a program
|
|
4686
|
-
* with no work left should exit.
|
|
4687
|
-
*/ const unreference = (channel)=>{
|
|
4674
|
+
const openBroadcastChannel = (channelKey)=>{
|
|
4675
|
+
if (typeof BroadcastChannel !== "function") {
|
|
4676
|
+
return null;
|
|
4677
|
+
}
|
|
4678
|
+
const channel = new BroadcastChannel(`__routier-schema-subscription-channel:${channelKey}`);
|
|
4688
4679
|
const maybeUnref = channel.unref;
|
|
4689
|
-
if (typeof maybeUnref ===
|
|
4680
|
+
if (typeof maybeUnref === "function") {
|
|
4690
4681
|
maybeUnref.call(channel);
|
|
4691
4682
|
}
|
|
4683
|
+
return channel;
|
|
4692
4684
|
};
|
|
4693
4685
|
class SchemaChannelSender {
|
|
4694
4686
|
broadcastChannel;
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4687
|
+
localReceiver;
|
|
4688
|
+
constructor(channelKey, localReceiver){
|
|
4689
|
+
this.broadcastChannel = openBroadcastChannel(channelKey);
|
|
4690
|
+
this.localReceiver = localReceiver;
|
|
4698
4691
|
}
|
|
4699
4692
|
send(changes) {
|
|
4700
|
-
this.broadcastChannel
|
|
4693
|
+
if (this.broadcastChannel != null) {
|
|
4694
|
+
this.broadcastChannel.postMessage(changes);
|
|
4695
|
+
return;
|
|
4696
|
+
}
|
|
4697
|
+
const copy = structuredClone(changes);
|
|
4698
|
+
setTimeout(()=>this.localReceiver.dispatch(copy), 0);
|
|
4701
4699
|
}
|
|
4702
4700
|
close() {
|
|
4703
|
-
this.broadcastChannel
|
|
4701
|
+
this.broadcastChannel?.close();
|
|
4704
4702
|
}
|
|
4705
4703
|
}
|
|
4706
4704
|
class SchemaChannelReceiver {
|
|
4707
4705
|
broadcastChannel;
|
|
4708
4706
|
subscriptions = [];
|
|
4709
4707
|
constructor(channelKey){
|
|
4710
|
-
this.broadcastChannel =
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
}
|
|
4708
|
+
this.broadcastChannel = openBroadcastChannel(channelKey);
|
|
4709
|
+
if (this.broadcastChannel != null) {
|
|
4710
|
+
this.broadcastChannel.onmessage = (e)=>this.dispatch(e.data);
|
|
4711
|
+
}
|
|
4712
|
+
}
|
|
4713
|
+
dispatch(changes) {
|
|
4714
|
+
const subscriptions = this.subscriptions;
|
|
4715
|
+
for(let i = 0, length = subscriptions.length; i < length; i++){
|
|
4716
|
+
subscriptions[i].action(changes);
|
|
4717
|
+
}
|
|
4720
4718
|
}
|
|
4721
4719
|
get listenerCount() {
|
|
4722
4720
|
return this.subscriptions.length;
|
|
@@ -4729,8 +4727,10 @@ class SchemaChannelReceiver {
|
|
|
4729
4727
|
}
|
|
4730
4728
|
close() {
|
|
4731
4729
|
this.subscriptions = [];
|
|
4732
|
-
this.broadcastChannel
|
|
4733
|
-
|
|
4730
|
+
if (this.broadcastChannel != null) {
|
|
4731
|
+
this.broadcastChannel.onmessage = null;
|
|
4732
|
+
this.broadcastChannel.close();
|
|
4733
|
+
}
|
|
4734
4734
|
}
|
|
4735
4735
|
}
|
|
4736
4736
|
class SubscriptionListener {
|