@byloth/core 2.1.5 → 2.1.6
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/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +26 -95
- package/dist/core.esm.js.map +1 -1
- package/dist/core.global.js +1 -1
- package/dist/core.global.js.map +1 -1
- package/dist/core.umd.cjs +1 -1
- package/dist/core.umd.cjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +4 -2
- package/src/models/callbacks/publisher.ts +149 -24
- package/src/models/callbacks/switchable-callback.ts +6 -6
- package/src/models/callbacks/types.ts +52 -20
- package/src/models/collections/map-view.ts +14 -15
- package/src/models/collections/set-view.ts +13 -16
- package/src/models/collections/types.ts +6 -6
- package/src/models/iterators/smart-async-iterator.ts +1 -1
- package/src/models/iterators/smart-iterator.ts +1 -1
- package/src/models/timers/clock.ts +3 -3
- package/src/models/timers/countdown.ts +4 -4
- package/src/models/timers/game-loop.ts +4 -4
- package/src/models/types.ts +9 -1
package/dist/core.esm.js
CHANGED
|
@@ -900,7 +900,7 @@ class u {
|
|
|
900
900
|
*
|
|
901
901
|
* for (const value of iterator)
|
|
902
902
|
* {
|
|
903
|
-
* if (value > 5) { break; } // Closing the iterator...
|
|
903
|
+
* if (value > 5) { break; } // "Closing the iterator..."
|
|
904
904
|
*
|
|
905
905
|
* console.log(value); // 1, 2, 3, 4, 5
|
|
906
906
|
* }
|
|
@@ -2824,7 +2824,7 @@ class d {
|
|
|
2824
2824
|
*
|
|
2825
2825
|
* for await (const value of iterator)
|
|
2826
2826
|
* {
|
|
2827
|
-
* if (value > 5) { break; } // Closing the iterator...
|
|
2827
|
+
* if (value > 5) { break; } // "Closing the iterator..."
|
|
2828
2828
|
*
|
|
2829
2829
|
* console.log(value); // 1, 2, 3, 4, 5
|
|
2830
2830
|
* }
|
|
@@ -3680,10 +3680,10 @@ const F = class F {
|
|
|
3680
3680
|
* const publisher = new Publisher();
|
|
3681
3681
|
* const context = publisher.createScope();
|
|
3682
3682
|
*
|
|
3683
|
-
* publisher.subscribe("player:death", () =>
|
|
3684
|
-
* context.subscribe("player:spawn", () =>
|
|
3683
|
+
* publisher.subscribe("player:death", () => console.log(`Player has died.`));
|
|
3684
|
+
* context.subscribe("player:spawn", () => console.log(`Player has spawned.`));
|
|
3685
3685
|
*
|
|
3686
|
-
* publisher.publish("player:spawn"); // Player has spawned.
|
|
3686
|
+
* publisher.publish("player:spawn"); // "Player has spawned."
|
|
3687
3687
|
* context.publish("player:death"); // * no output *
|
|
3688
3688
|
* ```
|
|
3689
3689
|
*
|
|
@@ -3694,69 +3694,20 @@ const F = class F {
|
|
|
3694
3694
|
* related callback signatures that can be subscribed to them.
|
|
3695
3695
|
* Default is `T`.
|
|
3696
3696
|
*
|
|
3697
|
-
* @template X An utility type that extends the `U` map with a wildcard event.
|
|
3698
|
-
*
|
|
3699
3697
|
* @return
|
|
3700
3698
|
* A new instance of the {@link Publisher} class that can be
|
|
3701
3699
|
* used to publish and subscribe events within a specific context.
|
|
3702
3700
|
*/
|
|
3703
3701
|
createScope() {
|
|
3704
|
-
const n = new F()
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3702
|
+
const n = new F();
|
|
3703
|
+
return this.subscribe("__internals__:clear", () => n.clear()), this.subscribe("*", (e, ...t) => {
|
|
3704
|
+
n.publish(e, ...t);
|
|
3705
|
+
}), n;
|
|
3708
3706
|
}
|
|
3709
|
-
/**
|
|
3710
|
-
* Publishes an event to all the subscribers.
|
|
3711
|
-
*
|
|
3712
|
-
* ---
|
|
3713
|
-
*
|
|
3714
|
-
* @example
|
|
3715
|
-
* ```ts
|
|
3716
|
-
* publisher.subscribe("player:move", (coords) => { [...] });
|
|
3717
|
-
* publisher.subscribe("player:move", ({ x, y }) => { [...] });
|
|
3718
|
-
* publisher.subscribe("player:move", (evt) => { [...] });
|
|
3719
|
-
*
|
|
3720
|
-
* publisher.publish("player:move", { x: 10, y: 20 });
|
|
3721
|
-
* ```
|
|
3722
|
-
*
|
|
3723
|
-
* ---
|
|
3724
|
-
*
|
|
3725
|
-
* @template K The key of the map containing the callback signature to publish.
|
|
3726
|
-
*
|
|
3727
|
-
* @param event The name of the event to publish.
|
|
3728
|
-
* @param args The arguments to pass to the subscribers.
|
|
3729
|
-
*
|
|
3730
|
-
* @returns An array containing the return values of all the subscribers.
|
|
3731
|
-
*/
|
|
3732
3707
|
publish(n, ...e) {
|
|
3733
3708
|
let t, s = this._subscribers.get(n);
|
|
3734
3709
|
return s ? t = s.slice().map((r) => r(...e)) : t = [], n.startsWith("__") || (s = this._subscribers.get("*"), s && s.slice().forEach((r) => r(n, ...e))), t;
|
|
3735
3710
|
}
|
|
3736
|
-
/**
|
|
3737
|
-
* Subscribes to an event and adds a subscriber to be executed when the event is published.
|
|
3738
|
-
*
|
|
3739
|
-
* ---
|
|
3740
|
-
*
|
|
3741
|
-
* @example
|
|
3742
|
-
* ```ts
|
|
3743
|
-
* let unsubscribe: () => void;
|
|
3744
|
-
* publisher.subscribe("player:death", unsubscribe);
|
|
3745
|
-
* publisher.subscribe("player:spawn", (evt) =>
|
|
3746
|
-
* {
|
|
3747
|
-
* unsubscribe = publisher.subscribe("player:move", ({ x, y }) => { [...] });
|
|
3748
|
-
* });
|
|
3749
|
-
* ```
|
|
3750
|
-
*
|
|
3751
|
-
* ---
|
|
3752
|
-
*
|
|
3753
|
-
* @template K The key of the map containing the callback signature to subscribe.
|
|
3754
|
-
*
|
|
3755
|
-
* @param event The name of the event to subscribe to.
|
|
3756
|
-
* @param subscriber The subscriber to execute when the event is published.
|
|
3757
|
-
*
|
|
3758
|
-
* @returns A function that can be used to unsubscribe the subscriber from the event.
|
|
3759
|
-
*/
|
|
3760
3711
|
subscribe(n, e) {
|
|
3761
3712
|
const t = this._subscribers.get(n) ?? [];
|
|
3762
3713
|
return t.push(e), this._subscribers.set(n, t), () => {
|
|
@@ -3766,26 +3717,6 @@ const F = class F {
|
|
|
3766
3717
|
t.splice(s, 1);
|
|
3767
3718
|
};
|
|
3768
3719
|
}
|
|
3769
|
-
/**
|
|
3770
|
-
* Unsubscribes from an event and removes a subscriber from being executed when the event is published.
|
|
3771
|
-
*
|
|
3772
|
-
* ---
|
|
3773
|
-
*
|
|
3774
|
-
* @example
|
|
3775
|
-
* ```ts
|
|
3776
|
-
* const onPlayerMove = ({ x, y }: Point) => { [...] };
|
|
3777
|
-
*
|
|
3778
|
-
* publisher.subscribe("player:spawn", (evt) => publisher.subscribe("player:move", onPlayerMove));
|
|
3779
|
-
* publisher.subscribe("player:death", () => publisher.unsubscribe("player:move", onPlayerMove));
|
|
3780
|
-
* ```
|
|
3781
|
-
*
|
|
3782
|
-
* ---
|
|
3783
|
-
*
|
|
3784
|
-
* @template K The key of the map containing the callback signature to unsubscribe.
|
|
3785
|
-
*
|
|
3786
|
-
* @param event The name of the event to unsubscribe from.
|
|
3787
|
-
* @param subscriber The subscriber to remove from the event.
|
|
3788
|
-
*/
|
|
3789
3720
|
unsubscribe(n, e) {
|
|
3790
3721
|
const t = this._subscribers.get(n);
|
|
3791
3722
|
if (!t)
|
|
@@ -3868,7 +3799,7 @@ class dt extends (Se = Ue, ve = Symbol.toStringTag, Se) {
|
|
|
3868
3799
|
*
|
|
3869
3800
|
* @example
|
|
3870
3801
|
* ```ts
|
|
3871
|
-
* window.addEventListener("pointerdown", () =>
|
|
3802
|
+
* window.addEventListener("pointerdown", () => onPointerMove.enable());
|
|
3872
3803
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3873
3804
|
* ```
|
|
3874
3805
|
*
|
|
@@ -3902,7 +3833,7 @@ class dt extends (Se = Ue, ve = Symbol.toStringTag, Se) {
|
|
|
3902
3833
|
* @example
|
|
3903
3834
|
* ```ts
|
|
3904
3835
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3905
|
-
* window.addEventListener("pointerup", () =>
|
|
3836
|
+
* window.addEventListener("pointerup", () => onPointerMove.disable());
|
|
3906
3837
|
* ```
|
|
3907
3838
|
*/
|
|
3908
3839
|
disable() {
|
|
@@ -3971,9 +3902,9 @@ class dt extends (Se = Ue, ve = Symbol.toStringTag, Se) {
|
|
|
3971
3902
|
*
|
|
3972
3903
|
* @example
|
|
3973
3904
|
* ```ts
|
|
3974
|
-
* window.addEventListener("pointerdown", () =>
|
|
3905
|
+
* window.addEventListener("pointerdown", () => onPointerMove.switch("pressed"));
|
|
3975
3906
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3976
|
-
* window.addEventListener("pointerup", () =>
|
|
3907
|
+
* window.addEventListener("pointerup", () => onPointerMove.switch("released"));
|
|
3977
3908
|
* ```
|
|
3978
3909
|
*
|
|
3979
3910
|
* ---
|
|
@@ -4094,8 +4025,8 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
4094
4025
|
* console.log(`Added ${key}: ${value}`);
|
|
4095
4026
|
* });
|
|
4096
4027
|
*
|
|
4097
|
-
* map.set("key1", 2); // Added key1: 2
|
|
4098
|
-
* map.set("answer", 42); // Added answer: 42
|
|
4028
|
+
* map.set("key1", 2); // "Added key1: 2"
|
|
4029
|
+
* map.set("answer", 42); // "Added answer: 42"
|
|
4099
4030
|
* map.set("key2", 4);
|
|
4100
4031
|
* map.set("key3", 8);
|
|
4101
4032
|
* ```
|
|
@@ -4105,7 +4036,7 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
4105
4036
|
* @template T The key of the map containing the callback signature to subscribe.
|
|
4106
4037
|
*
|
|
4107
4038
|
* @param event The name of the event to subscribe to.
|
|
4108
|
-
* @param
|
|
4039
|
+
* @param subscriber The callback to execute when the event is published.
|
|
4109
4040
|
*
|
|
4110
4041
|
* @returns A function that can be used to unsubscribe the callback from the event.
|
|
4111
4042
|
*/
|
|
@@ -4123,7 +4054,7 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
4123
4054
|
* const map = new MapView<string, number>();
|
|
4124
4055
|
*
|
|
4125
4056
|
* map.subscribe("entry:add", callback);
|
|
4126
|
-
* map.set("key1", 2); // Added key1: 2
|
|
4057
|
+
* map.set("key1", 2); // "Added key1: 2"
|
|
4127
4058
|
*
|
|
4128
4059
|
* map.unsubscribe("entry:add", callback);
|
|
4129
4060
|
* map.set("key2", 4);
|
|
@@ -4134,7 +4065,7 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
4134
4065
|
* @template T The key of the map containing the callback signature to unsubscribe.
|
|
4135
4066
|
*
|
|
4136
4067
|
* @param event The name of the event to unsubscribe from.
|
|
4137
|
-
* @param
|
|
4068
|
+
* @param subscriber The callback to remove from the event.
|
|
4138
4069
|
*/
|
|
4139
4070
|
unsubscribe(e, t) {
|
|
4140
4071
|
this._publisher.unsubscribe(e, t);
|
|
@@ -4247,8 +4178,8 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4247
4178
|
* console.log(`Added ${value}`);
|
|
4248
4179
|
* });
|
|
4249
4180
|
*
|
|
4250
|
-
* set.add(2); // Added 2
|
|
4251
|
-
* set.add(42); // Added 42
|
|
4181
|
+
* set.add(2); // "Added 2"
|
|
4182
|
+
* set.add(42); // "Added 42"
|
|
4252
4183
|
* set.add(4);
|
|
4253
4184
|
* set.add(8);
|
|
4254
4185
|
* ```
|
|
@@ -4258,7 +4189,7 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4258
4189
|
* @template K The key of the map containing the callback signature to subscribe.
|
|
4259
4190
|
*
|
|
4260
4191
|
* @param event The name of the event to subscribe to.
|
|
4261
|
-
* @param
|
|
4192
|
+
* @param subscriber The callback to execute when the event is published.
|
|
4262
4193
|
*
|
|
4263
4194
|
* @returns A function that can be used to unsubscribe the callback from the event.
|
|
4264
4195
|
*/
|
|
@@ -4276,7 +4207,7 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4276
4207
|
* const set = new SetView<number>();
|
|
4277
4208
|
*
|
|
4278
4209
|
* set.subscribe("entry:add", callback);
|
|
4279
|
-
* set.add(2); // Added 2
|
|
4210
|
+
* set.add(2); // "Added 2"
|
|
4280
4211
|
*
|
|
4281
4212
|
* set.unsubscribe("entry:add", callback);
|
|
4282
4213
|
* set.add(4);
|
|
@@ -4287,7 +4218,7 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4287
4218
|
* @template K The key of the map containing the callback signature to unsubscribe.
|
|
4288
4219
|
*
|
|
4289
4220
|
* @param event The name of the event to unsubscribe from.
|
|
4290
|
-
* @param
|
|
4221
|
+
* @param subscriber The callback to remove from the event.
|
|
4291
4222
|
*/
|
|
4292
4223
|
unsubscribe(e, t) {
|
|
4293
4224
|
this._publisher.unsubscribe(e, t);
|
|
@@ -5069,7 +5000,7 @@ class Ge {
|
|
|
5069
5000
|
*
|
|
5070
5001
|
* @example
|
|
5071
5002
|
* ```ts
|
|
5072
|
-
* loop.onStart(() =>
|
|
5003
|
+
* loop.onStart(() => console.log("The game loop has started."));
|
|
5073
5004
|
* ```
|
|
5074
5005
|
*
|
|
5075
5006
|
* ---
|
|
@@ -5088,7 +5019,7 @@ class Ge {
|
|
|
5088
5019
|
*
|
|
5089
5020
|
* @example
|
|
5090
5021
|
* ```ts
|
|
5091
|
-
* loop.onStop(() =>
|
|
5022
|
+
* loop.onStop(() => console.log("The game loop has stopped."));
|
|
5092
5023
|
* ```
|
|
5093
5024
|
*
|
|
5094
5025
|
* ---
|
|
@@ -5639,7 +5570,7 @@ function Ot(i) {
|
|
|
5639
5570
|
function qt(i) {
|
|
5640
5571
|
return `${i.charAt(0).toUpperCase()}${i.slice(1)}`;
|
|
5641
5572
|
}
|
|
5642
|
-
const $t = "2.1.
|
|
5573
|
+
const $t = "2.1.6";
|
|
5643
5574
|
export {
|
|
5644
5575
|
M as AggregatedAsyncIterator,
|
|
5645
5576
|
x as AggregatedIterator,
|