@hadoku/game-ui 0.1.215 → 0.1.216

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.
@@ -0,0 +1,14 @@
1
+ export interface Throttle {
2
+ /** A send is due: at once when `ms` has passed since the last (only from the timer when `deferred`), else when it has. */
3
+ soon(): void;
4
+ /** The send, now, dropping the one due. */
5
+ flush(): void;
6
+ /** Drops the send due, if any. */
7
+ cancel(): void;
8
+ /** A send went out another way: the next waits `ms` from now. */
9
+ sent(): void;
10
+ }
11
+ /** `deferred`: what is sent is read once the event that asked is through, so even a send due at once waits for the timer. */
12
+ export declare function throttle(ms: number, fire: () => boolean | void, { deferred }?: {
13
+ deferred?: boolean | undefined;
14
+ }): Throttle;
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Paces a send to at most one every `ms`. The caller keeps what is due (the latest point, a merged set) and
3
+ * `fire` sends it; this owns only the timer and when the last send went out. `fire` returns `false` when it
4
+ * sent nothing, so the window does not restart on it.
5
+ */
6
+ /** `deferred`: what is sent is read once the event that asked is through, so even a send due at once waits for the timer. */
7
+ export function throttle(ms, fire, { deferred = false } = {}) {
8
+ let last = 0;
9
+ let timer = null;
10
+ const cancel = () => {
11
+ if (timer !== null)
12
+ clearTimeout(timer);
13
+ timer = null;
14
+ };
15
+ const flush = () => {
16
+ cancel();
17
+ if (fire() !== false)
18
+ last = Date.now();
19
+ };
20
+ const soon = () => {
21
+ if (timer !== null)
22
+ return;
23
+ const wait = Math.max(0, ms - (Date.now() - last));
24
+ if (wait === 0 && !deferred)
25
+ flush();
26
+ else
27
+ timer = setTimeout(flush, wait);
28
+ };
29
+ return { soon, flush, cancel, sent: () => void (last = Date.now()) };
30
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-ui",
3
- "version": "0.1.215",
4
- "gitHead": "5fc2457da600b68050cd490e151fa006e7c1f23e",
3
+ "version": "0.1.216",
4
+ "gitHead": "b8f1d780b5f44ecdfcfd8bcf07f25b4ce7cdff20",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The browser parts any hosted game shares, above ui-shell: the room shell and session, seats and looks, the room route, the front page's generic pieces (gate, polls, gallery, patch notes), the bundle slot and relay channel a game's client mounts in, settings and trim screens, the HTTP and socket helpers, and the generic components (modal, popover, avatar, action button, radio cards). Knows no game; Magic's UI (games/magic/ui) plugs in, composed by the site (apps/ui). MIT; imports only react, react-dom, socket.io-client, @wolffm/* and the platform packages.",
@@ -53,8 +53,8 @@
53
53
  "react-dom": "^19.2.8"
54
54
  },
55
55
  "dependencies": {
56
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.219",
57
- "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.219",
56
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.220",
57
+ "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.220",
58
58
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
59
59
  "@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.152",
60
60
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.152",