@symbo.ls/fetch 3.14.664 → 3.14.666

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/inflight.js ADDED
@@ -0,0 +1,39 @@
1
+ 'use strict'
2
+
3
+ // --- Requests in flight ---
4
+ //
5
+ // Every request a REST adapter sends counts from its call until its body is
6
+ // read. smbls holds the hydration window over a pre-rendered page open until
7
+ // the first view's requests are done (smbls prerender.js), so a list that
8
+ // renders with its first data still adopts the server's rows.
9
+ //
10
+ // The count lives on globalThis under a Symbol.for slot, like the adapter
11
+ // registry (index.js CUSTOM_ADAPTERS): the copy of this package that smbls
12
+ // asks and the copy an app bundle sends through may be two module instances.
13
+
14
+ const KEY = Symbol.for('@symbo.ls/fetch:IN_FLIGHT')
15
+
16
+ const state = () => globalThis[KEY] || (globalThis[KEY] = { count: 0, waiters: [] })
17
+
18
+ export const requestStarted = () => {
19
+ state().count++
20
+ }
21
+
22
+ export const requestFinished = () => {
23
+ const s = state()
24
+ s.count = s.count > 0 ? s.count - 1 : 0
25
+ if (s.count === 0 && s.waiters.length) {
26
+ const waiters = s.waiters
27
+ s.waiters = []
28
+ for (const resolve of waiters) resolve()
29
+ }
30
+ }
31
+
32
+ /** How many REST adapter requests are in flight on this page. */
33
+ export const requestsInFlight = () => state().count
34
+
35
+ /** Resolves once no REST adapter request is in flight (at once when none is). */
36
+ export const whenRequestsIdle = () => {
37
+ const s = state()
38
+ return s.count === 0 ? Promise.resolve() : new Promise((resolve) => { s.waiters.push(resolve) })
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/fetch",
3
- "version": "3.14.664",
3
+ "version": "3.14.666",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",
@@ -41,8 +41,8 @@
41
41
  "adapters"
42
42
  ],
43
43
  "dependencies": {
44
- "@symbo.ls/signal": "^3.14.787",
45
- "@symbo.ls/utils": "^3.14.786"
44
+ "@symbo.ls/signal": "^3.14.789",
45
+ "@symbo.ls/utils": "^3.14.787"
46
46
  },
47
47
  "sideEffects": false,
48
48
  "publishConfig": {