@byloth/core 2.1.8 → 2.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byloth/core",
3
- "version": "2.1.8",
3
+ "version": "2.2.0",
4
4
  "description": "An unopinionated collection of useful functions and classes that I use widely in all my projects. 🔧",
5
5
  "keywords": [
6
6
  "Core",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export const VERSION = "2.1.8";
1
+ export const VERSION = "2.2.0";
2
2
 
3
3
  export type { Constructor, Interval, Timeout, ValueOf } from "./core/types.js";
4
4
 
@@ -61,7 +61,6 @@ export type {
61
61
  KeyedIteratee,
62
62
  KeyedReducer,
63
63
  KeyedTypeGuardPredicate,
64
- MapViewEventsMap,
65
64
  MaybeAsyncKeyedIteratee,
66
65
  MaybeAsyncKeyedReducer,
67
66
  MaybeAsyncGeneratorFunction,
@@ -77,7 +76,6 @@ export type {
77
76
  ReadonlySetView,
78
77
  Reducer,
79
78
  RejectedHandler,
80
- SetViewEventsMap,
81
79
  Subscribable,
82
80
  TypeGuardPredicate,
83
81
  WildcardEventsMap
@@ -1,9 +1,16 @@
1
1
  import Publisher from "../callbacks/publisher.js";
2
- import type { Callback, Subscribable } from "../types.js";
2
+ import type { Callback } from "../types.js";
3
3
 
4
4
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
5
  import type SetView from "./set-view.js";
6
- import type { MapViewEventsMap } from "./types.js";
6
+
7
+ interface MapViewEventsMap<K, V>
8
+ {
9
+ "add": (key: K, value: V) => void;
10
+ "remove": (key: K, value: V) => void;
11
+
12
+ "clear": () => void;
13
+ }
7
14
 
8
15
  /**
9
16
  * A wrapper class around the native {@link Map} class that provides additional functionality
@@ -17,7 +24,7 @@ import type { MapViewEventsMap } from "./types.js";
17
24
  * ```ts
18
25
  * const map = new MapView<string, number>();
19
26
  *
20
- * map.subscribe("entry:add", (key: string, value: number) => console.log(`Added ${key}: ${value}`));
27
+ * map.onAdd((key: string, value: number) => console.log(`Added ${key}: ${value}`));
21
28
  * map.set("answer", 42); // "Added answer: 42"
22
29
  * ```
23
30
  *
@@ -26,7 +33,7 @@ import type { MapViewEventsMap } from "./types.js";
26
33
  * @template K The type of the keys in the map.
27
34
  * @template V The type of the values in the map.
28
35
  */
29
- export default class MapView<K, V> extends Map<K, V> implements Subscribable<MapViewEventsMap<K, V>>
36
+ export default class MapView<K, V> extends Map<K, V>
30
37
  {
31
38
  /**
32
39
  * The internal {@link Publisher} instance used to publish events.
@@ -86,7 +93,7 @@ export default class MapView<K, V> extends Map<K, V> implements Subscribable<Map
86
93
  {
87
94
  super.set(key, value);
88
95
 
89
- this._publisher.publish("entry:add", key, value);
96
+ this._publisher.publish("add", key, value);
90
97
 
91
98
  return this;
92
99
  }
@@ -118,7 +125,7 @@ export default class MapView<K, V> extends Map<K, V> implements Subscribable<Map
118
125
 
119
126
  super.delete(key);
120
127
 
121
- this._publisher.publish("entry:remove", key, value);
128
+ this._publisher.publish("remove", key, value);
122
129
 
123
130
  return true;
124
131
  }
@@ -141,74 +148,77 @@ export default class MapView<K, V> extends Map<K, V> implements Subscribable<Map
141
148
  const size = this.size;
142
149
 
143
150
  super.clear();
144
- if (size > 0) { this._publisher.publish("collection:clear"); }
151
+ if (size > 0) { this._publisher.publish("clear"); }
145
152
  }
146
153
 
147
154
  /**
148
- * Subscribes to an event and adds a callback to be executed when the event is published.
155
+ * Subscribes to the `add` event of the map with a callback that will be executed when an entry is added.
149
156
  *
150
157
  * ---
151
158
  *
152
159
  * @example
153
160
  * ```ts
154
- * const map = new MapView<string, number>();
155
- * const unsubscribe = map.subscribe("entry:add", (key: string, value: number) =>
156
- * {
157
- * if (key === "answer") { unsubscribe(); }
158
- * console.log(`Added ${key}: ${value}`);
159
- * });
161
+ * map.onAdd((key, value) => console.log(`Added ${key}: ${value}`));
160
162
  *
161
163
  * map.set("key1", 2); // "Added key1: 2"
162
164
  * map.set("answer", 42); // "Added answer: 42"
163
- * map.set("key2", 4);
164
- * map.set("key3", 8);
165
165
  * ```
166
166
  *
167
167
  * ---
168
168
  *
169
- * @template T The key of the map containing the callback signature to subscribe.
170
- *
171
- * @param event The name of the event to subscribe to.
172
- * @param subscriber The callback to execute when the event is published.
169
+ * @param callback The callback that will be executed when an entry is added to the map.
173
170
  *
174
- * @returns A function that can be used to unsubscribe the callback from the event.
171
+ * @returns A function that can be used to unsubscribe from the event.
175
172
  */
176
- public subscribe<T extends keyof MapViewEventsMap<K, V>>(
177
- event: T & string, subscriber: MapViewEventsMap<K, V>[T]
178
- ): Callback
173
+ public onAdd(callback: (key: K, value: V) => void): Callback
179
174
  {
180
- return this._publisher.subscribe(event, subscriber);
175
+ return this._publisher.subscribe("add", callback);
181
176
  }
182
177
 
183
178
  /**
184
- * Unsubscribes from an event and removes a callback from being executed when the event is published.
179
+ * Subscribes to the `remove` event of the map with a callback that will be executed when an entry is removed.
185
180
  *
186
181
  * ---
187
182
  *
188
183
  * @example
189
184
  * ```ts
190
- * const callback = (key: string, value: number) => console.log(`Added ${key}: ${value}`);
191
- * const map = new MapView<string, number>();
185
+ * map.onRemove((key, value) => console.log(`Removed ${key}: ${value}`));
192
186
  *
193
- * map.subscribe("entry:add", callback);
194
- * map.set("key1", 2); // "Added key1: 2"
187
+ * map.delete("key1"); // "Removed key1: 2"
188
+ * map.delete("answer"); // "Removed answer: 42"
189
+ * ```
190
+ *
191
+ * ---
195
192
  *
196
- * map.unsubscribe("entry:add", callback);
197
- * map.set("key2", 4);
193
+ * @param callback The callback that will be executed when an entry is removed from the map.
194
+ *
195
+ * @returns A function that can be used to unsubscribe from the event.
196
+ */
197
+ public onRemove(callback: (key: K, value: V) => void): Callback
198
+ {
199
+ return this._publisher.subscribe("remove", callback);
200
+ }
201
+
202
+ /**
203
+ * Subscribes to the `clear` event of the map with a callback that will be executed when the map is cleared.
204
+ *
205
+ * ---
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * map.onClear(() => console.log("The map has all been cleared."));
210
+ * map.clear(); // "The map has all been cleared."
198
211
  * ```
199
212
  *
200
213
  * ---
201
214
  *
202
- * @template T The key of the map containing the callback signature to unsubscribe.
215
+ * @param callback The callback that will be executed when the map is cleared.
203
216
  *
204
- * @param event The name of the event to unsubscribe from.
205
- * @param subscriber The callback to remove from the event.
217
+ * @returns A function that can be used to unsubscribe from the event.
206
218
  */
207
- public unsubscribe<T extends keyof MapViewEventsMap<K, V>>(
208
- event: T & string, subscriber: MapViewEventsMap<K, V>[T]
209
- ): void
219
+ public onClear(callback: () => void): Callback
210
220
  {
211
- this._publisher.unsubscribe(event, subscriber);
221
+ return this._publisher.subscribe("clear", callback);
212
222
  }
213
223
 
214
224
  public override readonly [Symbol.toStringTag]: string = "MapView";
@@ -1,9 +1,16 @@
1
1
  import Publisher from "../callbacks/publisher.js";
2
- import type { Callback, Subscribable } from "../types.js";
2
+ import type { Callback } from "../types.js";
3
3
 
4
4
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
5
  import type MapView from "./map-view.js";
6
- import type { SetViewEventsMap } from "./types.js";
6
+
7
+ interface SetViewEventsMap<T>
8
+ {
9
+ "add": (value: T) => void;
10
+ "remove": (value: T) => void;
11
+
12
+ "clear": () => void;
13
+ }
7
14
 
8
15
  /**
9
16
  * A wrapper class around the native {@link Set} class that provides additional functionality
@@ -17,7 +24,7 @@ import type { SetViewEventsMap } from "./types.js";
17
24
  * ```ts
18
25
  * const set = new SetView<number>();
19
26
  *
20
- * set.subscribe("entry:add", (value: number) => console.log(`Added ${value}`));
27
+ * set.onAdd((value: number) => console.log(`Added ${value}`));
21
28
  * set.add(42); // "Added 42"
22
29
  * ```
23
30
  *
@@ -25,7 +32,7 @@ import type { SetViewEventsMap } from "./types.js";
25
32
  *
26
33
  * @template T The type of the values in the set.
27
34
  */
28
- export default class SetView<T> extends Set<T> implements Subscribable<SetViewEventsMap<T>>
35
+ export default class SetView<T> extends Set<T>
29
36
  {
30
37
  /**
31
38
  * The internal {@link Publisher} instance used to publish events.
@@ -84,7 +91,7 @@ export default class SetView<T> extends Set<T> implements Subscribable<SetViewEv
84
91
  {
85
92
  super.add(value);
86
93
 
87
- this._publisher.publish("entry:add", value);
94
+ this._publisher.publish("add", value);
88
95
 
89
96
  return this;
90
97
  }
@@ -112,7 +119,7 @@ export default class SetView<T> extends Set<T> implements Subscribable<SetViewEv
112
119
  public override delete(value: T): boolean
113
120
  {
114
121
  const result = super.delete(value);
115
- if (result) { this._publisher.publish("entry:remove", value); }
122
+ if (result) { this._publisher.publish("remove", value); }
116
123
 
117
124
  return result;
118
125
  }
@@ -135,72 +142,77 @@ export default class SetView<T> extends Set<T> implements Subscribable<SetViewEv
135
142
  const size = this.size;
136
143
 
137
144
  super.clear();
138
- if (size > 0) { this._publisher.publish("collection:clear"); }
145
+ if (size > 0) { this._publisher.publish("clear"); }
139
146
  }
140
147
 
141
148
  /**
142
- * Subscribes to an event and adds a callback to be executed when the event is published.
149
+ * Subscribes to the `add` event of the set with a callback that will be executed when a value is added.
143
150
  *
144
151
  * ---
145
152
  *
146
153
  * @example
147
154
  * ```ts
148
- * const set = new SetView<number>();
149
- * const unsubscribe = set.subscribe("entry:add", (value: number) =>
150
- * {
151
- * if (value === 42) { unsubscribe(); }
152
- * console.log(`Added ${value}`);
153
- * });
155
+ * set.onAdd((value) => console.log(`Added ${value}`));
154
156
  *
155
157
  * set.add(2); // "Added 2"
156
158
  * set.add(42); // "Added 42"
157
- * set.add(4);
158
- * set.add(8);
159
159
  * ```
160
160
  *
161
161
  * ---
162
162
  *
163
- * @template K The key of the map containing the callback signature to subscribe.
164
- *
165
- * @param event The name of the event to subscribe to.
166
- * @param subscriber The callback to execute when the event is published.
163
+ * @param callback The callback that will be executed when a value is added to the set.
167
164
  *
168
- * @returns A function that can be used to unsubscribe the callback from the event.
165
+ * @returns A function that can be used to unsubscribe from the event.
169
166
  */
170
- public subscribe<K extends keyof SetViewEventsMap<T>>(
171
- event: K & string, subscriber: SetViewEventsMap<T>[K]
172
- ): Callback
167
+ public onAdd(callback: (value: T) => void): Callback
173
168
  {
174
- return this._publisher.subscribe(event, subscriber);
169
+ return this._publisher.subscribe("add", callback);
175
170
  }
176
171
 
177
172
  /**
178
- * Unsubscribes from an event and removes a callback from being executed when the event is published.
173
+ * Subscribes to the `remove` event of the set with a callback that will be executed when a value is removed.
179
174
  *
180
175
  * ---
181
176
  *
182
177
  * @example
183
178
  * ```ts
184
- * const callback = (value: number) => console.log(`Added ${value}`);
185
- * const set = new SetView<number>();
179
+ * set.onRemove((value) => console.log(`Removed ${value}`));
186
180
  *
187
- * set.subscribe("entry:add", callback);
188
- * set.add(2); // "Added 2"
181
+ * set.delete(2); // "Removed 2"
182
+ * set.delete(42); // "Removed 42"
183
+ * ```
184
+ *
185
+ * ---
189
186
  *
190
- * set.unsubscribe("entry:add", callback);
191
- * set.add(4);
187
+ * @param callback The callback that will be executed when a value is removed from the set.
188
+ *
189
+ * @returns A function that can be used to unsubscribe from the event.
190
+ */
191
+ public onRemove(callback: (value: T) => void): Callback
192
+ {
193
+ return this._publisher.subscribe("remove", callback);
194
+ }
195
+
196
+ /**
197
+ * Subscribes to the `clear` event of the set with a callback that will be executed when the set is cleared.
198
+ *
199
+ * ---
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * set.onClear(() => console.log("The set has all been cleared."));
204
+ * set.clear(); // "The set has all been cleared."
192
205
  * ```
193
206
  *
194
207
  * ---
195
208
  *
196
- * @template K The key of the map containing the callback signature to unsubscribe.
209
+ * @param callback The callback that will be executed when the set is cleared.
197
210
  *
198
- * @param event The name of the event to unsubscribe from.
199
- * @param subscriber The callback to remove from the event.
211
+ * @returns A function that can be used to unsubscribe from the event.
200
212
  */
201
- public unsubscribe<K extends keyof SetViewEventsMap<T>>(event: K & string, subscriber: SetViewEventsMap<T>[K]): void
213
+ public onClear(callback: () => void): Callback
202
214
  {
203
- this._publisher.unsubscribe(event, subscriber);
215
+ return this._publisher.subscribe("clear", callback);
204
216
  }
205
217
 
206
218
  public override readonly [Symbol.toStringTag]: string = "SetView";
@@ -6,25 +6,6 @@ import type MapView from "./map-view.js";
6
6
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
7
  import type SetView from "./set-view.js";
8
8
 
9
- /**
10
- * A type that represents the map of events published by a {@link MapView} object.
11
- * See also {@link SetViewEventsMap}.
12
- *
13
- * The keys of the map are the event names while the values are the callback function signatures.
14
- *
15
- * ---
16
- *
17
- * @template K The type of the keys in the map.
18
- * @template V The type of the values in the map.
19
- */
20
- export interface MapViewEventsMap<K, V>
21
- {
22
- "entry:add": (key: K, value: V) => void;
23
- "entry:remove": (key: K, value: V) => void;
24
-
25
- "collection:clear": () => void;
26
- }
27
-
28
9
  /**
29
10
  * An utility type that represents a read-only {@link MapView} object.
30
11
  * See also {@link ReadonlySetView}.
@@ -40,79 +21,65 @@ export interface MapViewEventsMap<K, V>
40
21
  export interface ReadonlyMapView<K, V> extends ReadonlyMap<K, V>
41
22
  {
42
23
  /**
43
- * Subscribes to an event and adds a callback to be executed when the event is published.
24
+ * Subscribes to the `add` event of the map with a callback that will be executed when an entry is added.
44
25
  *
45
26
  * ---
46
27
  *
47
28
  * @example
48
29
  * ```ts
49
- * const map = new MapView<string, number>();
50
- * const unsubscribe = map.subscribe("entry:add", (key: string, value: number) =>
51
- * {
52
- * if (key === "answer") { unsubscribe(); }
53
- * console.log(`Added ${key}: ${value}`);
54
- * });
30
+ * map.onAdd((key, value) => console.log(`Added ${key}: ${value}`));
55
31
  *
56
32
  * map.set("key1", 2); // "Added key1: 2"
57
33
  * map.set("answer", 42); // "Added answer: 42"
58
- * map.set("key2", 4);
59
- * map.set("key3", 8);
60
34
  * ```
61
35
  *
62
36
  * ---
63
37
  *
64
- * @template T The key of the map containing the callback signature to subscribe.
65
- *
66
- * @param event The name of the event to subscribe to.
67
- * @param callback The callback to execute when the event is published.
38
+ * @param callback The callback that will be executed when an entry is added to the map.
68
39
  *
69
- * @returns A function that can be used to unsubscribe the callback from the event.
40
+ * @returns A function that can be used to unsubscribe from the event.
70
41
  */
71
- subscribe<T extends keyof MapViewEventsMap<K, V>>(event: T & string, callback: MapViewEventsMap<K, V>[T]): Callback;
42
+ onAdd(callback: (key: K, value: V) => void): Callback;
72
43
 
73
44
  /**
74
- * Unsubscribes from an event and removes a callback from being executed when the event is published.
45
+ * Subscribes to the `remove` event of the map with a callback that will be executed when an entry is removed.
75
46
  *
76
47
  * ---
77
48
  *
78
49
  * @example
79
50
  * ```ts
80
- * const callback = (key: string, value: number) => console.log(`Added ${key}: ${value}`);
81
- * const map = new MapView<string, number>();
82
- *
83
- * map.subscribe("entry:add", callback);
84
- * map.set("key1", 2); // "Added key1: 2"
51
+ * map.onRemove((key, value) => console.log(`Removed ${key}: ${value}`));
85
52
  *
86
- * map.unsubscribe("entry:add", callback);
87
- * map.set("key2", 4);
53
+ * map.delete("key1"); // "Removed key1: 2"
54
+ * map.delete("answer"); // "Removed answer: 42"
88
55
  * ```
89
56
  *
90
57
  * ---
91
58
  *
92
- * @template T The key of the map containing the callback signature to unsubscribe.
59
+ * @param callback The callback that will be executed when an entry is removed from the map.
93
60
  *
94
- * @param event The name of the event to unsubscribe from.
95
- * @param callback The callback to remove from the event.
61
+ * @returns A function that can be used to unsubscribe from the event.
96
62
  */
97
- unsubscribe<T extends keyof MapViewEventsMap<K, V>>(event: T & string, callback: MapViewEventsMap<K, V>[T]): void;
98
- }
99
-
100
- /**
101
- * A type that represents the map of events published by a {@link SetView} object.
102
- * See also {@link MapViewEventsMap}.
103
- *
104
- * The keys of the map are the event names while the values are the callback function signatures.
105
- *
106
- * ---
107
- *
108
- * @template T The type of the values in the set.
109
- */
110
- export interface SetViewEventsMap<T>
111
- {
112
- "entry:add": (value: T) => void;
113
- "entry:remove": (value: T) => void;
63
+ onRemove(callback: (key: K, value: V) => void): Callback;
114
64
 
115
- "collection:clear": () => void;
65
+ /**
66
+ * Subscribes to the `clear` event of the map with a callback that will be executed when the map is cleared.
67
+ *
68
+ * ---
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * map.onClear(() => console.log("The map has all been cleared."));
73
+ * map.clear();
74
+ * ```
75
+ *
76
+ * ---
77
+ *
78
+ * @param callback The callback that will be executed when the map is cleared.
79
+ *
80
+ * @returns A function that can be used to unsubscribe from the event.
81
+ */
82
+ onClear(callback: () => void): Callback;
116
83
  }
117
84
 
118
85
  /**
@@ -129,59 +96,63 @@ export interface SetViewEventsMap<T>
129
96
  export interface ReadonlySetView<T> extends ReadonlySet<T>
130
97
  {
131
98
  /**
132
- * Subscribes to an event and adds a callback to be executed when the event is published.
99
+ * Subscribes to the `add` event of the set with a callback that will be executed when a value is added.
133
100
  *
134
101
  * ---
135
102
  *
136
103
  * @example
137
104
  * ```ts
138
- * const set = new SetView<number>();
139
- * const unsubscribe = set.subscribe("entry:add", (value: number) =>
140
- * {
141
- * if (value === 42) { unsubscribe(); }
142
- * console.log(`Added ${value}`);
143
- * });
105
+ * set.onAdd((value) => console.log(`Added ${value}`));
144
106
  *
145
107
  * set.add(2); // "Added 2"
146
108
  * set.add(42); // "Added 42"
147
- * set.add(4);
148
- * set.add(8);
149
109
  * ```
150
110
  *
151
111
  * ---
152
112
  *
153
- * @template K The key of the map containing the callback signature to subscribe.
154
- *
155
- * @param event The name of the event to subscribe to.
156
- * @param callback The callback to execute when the event is published.
113
+ * @param callback The callback that will be executed when a value is added to the set.
157
114
  *
158
- * @returns A function that can be used to unsubscribe the callback from the event.
115
+ * @returns A function that can be used to unsubscribe from the event.
159
116
  */
160
- subscribe<K extends keyof SetViewEventsMap<T>>(event: K & string, callback: SetViewEventsMap<T>[K]): Callback;
117
+ onAdd(callback: (value: T) => void): Callback;
161
118
 
162
119
  /**
163
- * Unsubscribes from an event and removes a callback from being executed when the event is published.
120
+ * Subscribes to the `remove` event of the set with a callback that will be executed when a value is removed.
164
121
  *
165
122
  * ---
166
123
  *
167
124
  * @example
168
125
  * ```ts
169
- * const callback = (value: number) => console.log(`Added ${value}`);
170
- * const set = new SetView<number>();
126
+ * set.onRemove((value) => console.log(`Removed ${value}`));
171
127
  *
172
- * set.subscribe("entry:add", callback);
173
- * set.add(2); // "Added 2"
128
+ * set.delete(2); // "Removed 2"
129
+ * set.delete(42); // "Removed 42"
130
+ * ```
131
+ *
132
+ * ---
133
+ *
134
+ * @param callback The callback that will be executed when a value is removed from the set.
135
+ *
136
+ * @returns A function that can be used to unsubscribe from the event.
137
+ */
138
+ onRemove(callback: (value: T) => void): Callback;
139
+
140
+ /**
141
+ * Subscribes to the `clear` event of the set with a callback that will be executed when the set is cleared.
142
+ *
143
+ * ---
174
144
  *
175
- * set.unsubscribe("entry:add", callback);
176
- * set.add(4);
145
+ * @example
146
+ * ```ts
147
+ * set.onClear(() => console.log("The set has all been cleared."));
148
+ * set.clear(); // "The set has all been cleared."
177
149
  * ```
178
150
  *
179
151
  * ---
180
152
  *
181
- * @template K The key of the map containing the callback signature to unsubscribe.
153
+ * @param callback The callback that will be executed when the set is cleared.
182
154
  *
183
- * @param event The name of the event to unsubscribe from.
184
- * @param callback The callback to remove from the event.
155
+ * @returns A function that can be used to unsubscribe from the event.
185
156
  */
186
- unsubscribe<K extends keyof SetViewEventsMap<T>>(event: K & string, callback: SetViewEventsMap<T>[K]): void;
157
+ onClear(callback: () => void): Callback;
187
158
  }
@@ -8,9 +8,9 @@ import GameLoop from "./game-loop.js";
8
8
 
9
9
  interface ClockEventsMap
10
10
  {
11
- start: () => void;
12
- stop: () => void;
13
- tick: (elapsedTime: number) => void;
11
+ "start": () => void;
12
+ "stop": () => void;
13
+ "tick": (elapsedTime: number) => void;
14
14
  }
15
15
 
16
16
  /**
@@ -14,9 +14,6 @@ interface CountdownEventsMap
14
14
  stop: (reason: unknown) => void;
15
15
  tick: (remainingTime: number) => void;
16
16
  expire: () => void;
17
-
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- [key: string]: Callback<any[], any>;
20
17
  }
21
18
 
22
19
  /**
@@ -211,28 +208,6 @@ export default class Countdown extends GameLoop
211
208
  this._publisher.publish("stop", reason);
212
209
  }
213
210
 
214
- /**
215
- * Subscribes to the `expire` event of the countdown.
216
- *
217
- * ---
218
- *
219
- * @example
220
- * ```ts
221
- * countdown.onExpire(() => { [...] }); // This callback will be executed once the countdown has expired.
222
- * countdown.start();
223
- * ```
224
- *
225
- * ---
226
- *
227
- * @param callback The callback that will be executed when the countdown expires.
228
- *
229
- * @returns A function that can be used to unsubscribe from the event.
230
- */
231
- public onExpire(callback: Callback): Callback
232
- {
233
- return this._publisher.subscribe("expire", callback);
234
- }
235
-
236
211
  /**
237
212
  * Subscribes to the `tick` event of the countdown.
238
213
  *
@@ -273,5 +248,27 @@ export default class Countdown extends GameLoop
273
248
  });
274
249
  }
275
250
 
251
+ /**
252
+ * Subscribes to the `expire` event of the countdown.
253
+ *
254
+ * ---
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * countdown.onExpire(() => { [...] }); // This callback will be executed once the countdown has expired.
259
+ * countdown.start();
260
+ * ```
261
+ *
262
+ * ---
263
+ *
264
+ * @param callback The callback that will be executed when the countdown expires.
265
+ *
266
+ * @returns A function that can be used to unsubscribe from the event.
267
+ */
268
+ public onExpire(callback: Callback): Callback
269
+ {
270
+ return this._publisher.subscribe("expire", callback);
271
+ }
272
+
276
273
  public override readonly [Symbol.toStringTag]: string = "Countdown";
277
274
  }