@byloth/core 2.1.5 → 2.1.7
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 +30 -98
- 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/callable-object.ts +3 -3
- package/src/models/callbacks/publisher.ts +103 -28
- package/src/models/callbacks/switchable-callback.ts +7 -7
- 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,83 +3680,35 @@ 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
|
*
|
|
3690
3690
|
* ---
|
|
3691
3691
|
*
|
|
3692
3692
|
* @template U
|
|
3693
|
-
* A map containing the names of the emittable events and
|
|
3694
|
-
* related callback signatures that can be subscribed to them.
|
|
3695
|
-
* Default is `
|
|
3696
|
-
*
|
|
3697
|
-
* @template X An utility type that extends the `U` map with a wildcard event.
|
|
3693
|
+
* A map containing the additional names of the emittable events and
|
|
3694
|
+
* the related callback signatures that can be subscribed to them.
|
|
3695
|
+
* Default is `{ }`.
|
|
3698
3696
|
*
|
|
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
|
*/
|
|
3701
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
3703
3702
|
createScope() {
|
|
3704
|
-
const n = new F()
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3703
|
+
const n = new F();
|
|
3704
|
+
return this.subscribe("__internals__:clear", () => n.clear()), this.subscribe("*", (e, ...t) => {
|
|
3705
|
+
n.publish(e, ...t);
|
|
3706
|
+
}), n;
|
|
3708
3707
|
}
|
|
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
3708
|
publish(n, ...e) {
|
|
3733
3709
|
let t, s = this._subscribers.get(n);
|
|
3734
3710
|
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
3711
|
}
|
|
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
3712
|
subscribe(n, e) {
|
|
3761
3713
|
const t = this._subscribers.get(n) ?? [];
|
|
3762
3714
|
return t.push(e), this._subscribers.set(n, t), () => {
|
|
@@ -3766,26 +3718,6 @@ const F = class F {
|
|
|
3766
3718
|
t.splice(s, 1);
|
|
3767
3719
|
};
|
|
3768
3720
|
}
|
|
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
3721
|
unsubscribe(n, e) {
|
|
3790
3722
|
const t = this._subscribers.get(n);
|
|
3791
3723
|
if (!t)
|
|
@@ -3868,7 +3800,7 @@ class dt extends (Se = Ue, ve = Symbol.toStringTag, Se) {
|
|
|
3868
3800
|
*
|
|
3869
3801
|
* @example
|
|
3870
3802
|
* ```ts
|
|
3871
|
-
* window.addEventListener("pointerdown", () =>
|
|
3803
|
+
* window.addEventListener("pointerdown", () => onPointerMove.enable());
|
|
3872
3804
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3873
3805
|
* ```
|
|
3874
3806
|
*
|
|
@@ -3902,7 +3834,7 @@ class dt extends (Se = Ue, ve = Symbol.toStringTag, Se) {
|
|
|
3902
3834
|
* @example
|
|
3903
3835
|
* ```ts
|
|
3904
3836
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3905
|
-
* window.addEventListener("pointerup", () =>
|
|
3837
|
+
* window.addEventListener("pointerup", () => onPointerMove.disable());
|
|
3906
3838
|
* ```
|
|
3907
3839
|
*/
|
|
3908
3840
|
disable() {
|
|
@@ -3971,9 +3903,9 @@ class dt extends (Se = Ue, ve = Symbol.toStringTag, Se) {
|
|
|
3971
3903
|
*
|
|
3972
3904
|
* @example
|
|
3973
3905
|
* ```ts
|
|
3974
|
-
* window.addEventListener("pointerdown", () =>
|
|
3906
|
+
* window.addEventListener("pointerdown", () => onPointerMove.switch("pressed"));
|
|
3975
3907
|
* window.addEventListener("pointermove", onPointerMove);
|
|
3976
|
-
* window.addEventListener("pointerup", () =>
|
|
3908
|
+
* window.addEventListener("pointerup", () => onPointerMove.switch("released"));
|
|
3977
3909
|
* ```
|
|
3978
3910
|
*
|
|
3979
3911
|
* ---
|
|
@@ -4094,8 +4026,8 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
4094
4026
|
* console.log(`Added ${key}: ${value}`);
|
|
4095
4027
|
* });
|
|
4096
4028
|
*
|
|
4097
|
-
* map.set("key1", 2); // Added key1: 2
|
|
4098
|
-
* map.set("answer", 42); // Added answer: 42
|
|
4029
|
+
* map.set("key1", 2); // "Added key1: 2"
|
|
4030
|
+
* map.set("answer", 42); // "Added answer: 42"
|
|
4099
4031
|
* map.set("key2", 4);
|
|
4100
4032
|
* map.set("key3", 8);
|
|
4101
4033
|
* ```
|
|
@@ -4105,7 +4037,7 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
4105
4037
|
* @template T The key of the map containing the callback signature to subscribe.
|
|
4106
4038
|
*
|
|
4107
4039
|
* @param event The name of the event to subscribe to.
|
|
4108
|
-
* @param
|
|
4040
|
+
* @param subscriber The callback to execute when the event is published.
|
|
4109
4041
|
*
|
|
4110
4042
|
* @returns A function that can be used to unsubscribe the callback from the event.
|
|
4111
4043
|
*/
|
|
@@ -4123,7 +4055,7 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
4123
4055
|
* const map = new MapView<string, number>();
|
|
4124
4056
|
*
|
|
4125
4057
|
* map.subscribe("entry:add", callback);
|
|
4126
|
-
* map.set("key1", 2); // Added key1: 2
|
|
4058
|
+
* map.set("key1", 2); // "Added key1: 2"
|
|
4127
4059
|
*
|
|
4128
4060
|
* map.unsubscribe("entry:add", callback);
|
|
4129
4061
|
* map.set("key2", 4);
|
|
@@ -4134,7 +4066,7 @@ class wt extends (Te = Map, ke = Symbol.toStringTag, Te) {
|
|
|
4134
4066
|
* @template T The key of the map containing the callback signature to unsubscribe.
|
|
4135
4067
|
*
|
|
4136
4068
|
* @param event The name of the event to unsubscribe from.
|
|
4137
|
-
* @param
|
|
4069
|
+
* @param subscriber The callback to remove from the event.
|
|
4138
4070
|
*/
|
|
4139
4071
|
unsubscribe(e, t) {
|
|
4140
4072
|
this._publisher.unsubscribe(e, t);
|
|
@@ -4247,8 +4179,8 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4247
4179
|
* console.log(`Added ${value}`);
|
|
4248
4180
|
* });
|
|
4249
4181
|
*
|
|
4250
|
-
* set.add(2); // Added 2
|
|
4251
|
-
* set.add(42); // Added 42
|
|
4182
|
+
* set.add(2); // "Added 2"
|
|
4183
|
+
* set.add(42); // "Added 42"
|
|
4252
4184
|
* set.add(4);
|
|
4253
4185
|
* set.add(8);
|
|
4254
4186
|
* ```
|
|
@@ -4258,7 +4190,7 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4258
4190
|
* @template K The key of the map containing the callback signature to subscribe.
|
|
4259
4191
|
*
|
|
4260
4192
|
* @param event The name of the event to subscribe to.
|
|
4261
|
-
* @param
|
|
4193
|
+
* @param subscriber The callback to execute when the event is published.
|
|
4262
4194
|
*
|
|
4263
4195
|
* @returns A function that can be used to unsubscribe the callback from the event.
|
|
4264
4196
|
*/
|
|
@@ -4276,7 +4208,7 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4276
4208
|
* const set = new SetView<number>();
|
|
4277
4209
|
*
|
|
4278
4210
|
* set.subscribe("entry:add", callback);
|
|
4279
|
-
* set.add(2); // Added 2
|
|
4211
|
+
* set.add(2); // "Added 2"
|
|
4280
4212
|
*
|
|
4281
4213
|
* set.unsubscribe("entry:add", callback);
|
|
4282
4214
|
* set.add(4);
|
|
@@ -4287,7 +4219,7 @@ class mt extends (Me = Set, Ee = Symbol.toStringTag, Me) {
|
|
|
4287
4219
|
* @template K The key of the map containing the callback signature to unsubscribe.
|
|
4288
4220
|
*
|
|
4289
4221
|
* @param event The name of the event to unsubscribe from.
|
|
4290
|
-
* @param
|
|
4222
|
+
* @param subscriber The callback to remove from the event.
|
|
4291
4223
|
*/
|
|
4292
4224
|
unsubscribe(e, t) {
|
|
4293
4225
|
this._publisher.unsubscribe(e, t);
|
|
@@ -5069,7 +5001,7 @@ class Ge {
|
|
|
5069
5001
|
*
|
|
5070
5002
|
* @example
|
|
5071
5003
|
* ```ts
|
|
5072
|
-
* loop.onStart(() =>
|
|
5004
|
+
* loop.onStart(() => console.log("The game loop has started."));
|
|
5073
5005
|
* ```
|
|
5074
5006
|
*
|
|
5075
5007
|
* ---
|
|
@@ -5088,7 +5020,7 @@ class Ge {
|
|
|
5088
5020
|
*
|
|
5089
5021
|
* @example
|
|
5090
5022
|
* ```ts
|
|
5091
|
-
* loop.onStop(() =>
|
|
5023
|
+
* loop.onStop(() => console.log("The game loop has stopped."));
|
|
5092
5024
|
* ```
|
|
5093
5025
|
*
|
|
5094
5026
|
* ---
|
|
@@ -5639,7 +5571,7 @@ function Ot(i) {
|
|
|
5639
5571
|
function qt(i) {
|
|
5640
5572
|
return `${i.charAt(0).toUpperCase()}${i.slice(1)}`;
|
|
5641
5573
|
}
|
|
5642
|
-
const $t = "2.1.
|
|
5574
|
+
const $t = "2.1.7";
|
|
5643
5575
|
export {
|
|
5644
5576
|
M as AggregatedAsyncIterator,
|
|
5645
5577
|
x as AggregatedIterator,
|