@fullstackunicorn/webapp 2.0.2 → 2.0.3
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/load/Load.js +12 -4
- package/load/engine.js +6 -4
- package/load/resources.js +2 -1
- package/package.json +1 -1
- package/package.md +3 -1
package/load/Load.js
CHANGED
|
@@ -23,7 +23,7 @@ export const Load = ({ onReady = ready }) => {
|
|
|
23
23
|
useEffect(() => {
|
|
24
24
|
let active = true
|
|
25
25
|
const controller = new AbortController()
|
|
26
|
-
let timer, running = false
|
|
26
|
+
let timer, running = false, prepared = false
|
|
27
27
|
const schedule = () => {
|
|
28
28
|
clearTimeout(timer)
|
|
29
29
|
if (active && visibility.isVisible()) timer = setTimeout(check, engine.interval)
|
|
@@ -34,10 +34,18 @@ export const Load = ({ onReady = ready }) => {
|
|
|
34
34
|
try {
|
|
35
35
|
await priority.ready()
|
|
36
36
|
if (!active) return
|
|
37
|
-
|
|
38
|
-
if (active)
|
|
37
|
+
await engine.run(lang, dimensionsRef.current.width, controller.signal, async refreshNeeded => {
|
|
38
|
+
if (prepared || !active) return
|
|
39
|
+
if (refreshNeeded) await refresh(lang)
|
|
40
|
+
if (active) {
|
|
41
|
+
prepared = true
|
|
42
|
+
onReady(true)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
if (!prepared && active) {
|
|
46
|
+
prepared = true
|
|
47
|
+
onReady(true)
|
|
39
48
|
}
|
|
40
|
-
if (active) onReady(true)
|
|
41
49
|
} catch (error) { if (error.name !== 'AbortError') console.error('load-failed', error) }
|
|
42
50
|
finally {
|
|
43
51
|
running = false
|
package/load/engine.js
CHANGED
|
@@ -43,16 +43,16 @@ class Engine {
|
|
|
43
43
|
return !previous?.complete || this.signature(previous.state) !== this.signature(current)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
run = async (lang, width, signal) => {
|
|
46
|
+
run = async (lang, width, signal, onResources) => {
|
|
47
47
|
const previous = this.jobs.get(lang)
|
|
48
48
|
if (previous) await previous.catch(error => { if (error.name !== 'AbortError') throw error })
|
|
49
49
|
if (signal?.aborted) throw new DOMException('Aborted', 'AbortError')
|
|
50
|
-
const job = this.check(lang, width, signal).finally(() => { if (this.jobs.get(lang) === job) this.jobs.delete(lang) })
|
|
50
|
+
const job = this.check(lang, width, signal, onResources).finally(() => { if (this.jobs.get(lang) === job) this.jobs.delete(lang) })
|
|
51
51
|
this.jobs.set(lang, job)
|
|
52
52
|
return job
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
check = async (lang, width, signal) => {
|
|
55
|
+
check = async (lang, width, signal, onResources) => {
|
|
56
56
|
await cache.initialize()
|
|
57
57
|
const key = this.key(lang)
|
|
58
58
|
const before = await get(key) || { state: null, complete: false, items: {}, geometry: null }
|
|
@@ -80,16 +80,18 @@ class Engine {
|
|
|
80
80
|
const preload = response?.preload
|
|
81
81
|
if (!response?.current?.site || !preload || !Array.isArray(preload.delete)
|
|
82
82
|
|| !Array.isArray(preload.replace) || !Array.isArray(preload.new)) throw new Error('Invalid Data load bundle')
|
|
83
|
-
nextItems = await resources.apply(preload, width, nextItems, signal)
|
|
84
83
|
refresh = [...preload.delete, ...preload.replace, ...preload.new].some(value => {
|
|
85
84
|
const item = typeof value === 'string' ? before.items?.[value] : value
|
|
86
85
|
return item?.kind === 'resource'
|
|
87
86
|
})
|
|
87
|
+
nextItems = await resources.apply(preload, width, nextItems, signal, () => onResources?.(refresh))
|
|
88
88
|
await set(key, { state: response.current, complete: true, items: nextItems, geometry })
|
|
89
89
|
} else if (geometryChanged) {
|
|
90
|
+
await onResources?.(false)
|
|
90
91
|
nextItems = await resources.resize(nextItems, width, signal)
|
|
91
92
|
await set(key, { ...before, state: current, complete: true, items: nextItems, geometry })
|
|
92
93
|
} else {
|
|
94
|
+
await onResources?.(false)
|
|
93
95
|
await set(key, { ...before, state: current })
|
|
94
96
|
}
|
|
95
97
|
|
package/load/resources.js
CHANGED
|
@@ -63,7 +63,7 @@ class Resources {
|
|
|
63
63
|
return { ...item, size: selected.size, url: selected.src, version: selected.version, hash: selected.hash }
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
apply = async (preload, width, current = {}, signal) => {
|
|
66
|
+
apply = async (preload, width, current = {}, signal, onResources) => {
|
|
67
67
|
const next = { ...current }
|
|
68
68
|
for (const key of preload.delete || []) {
|
|
69
69
|
await this.remove(next[key])
|
|
@@ -77,6 +77,7 @@ class Resources {
|
|
|
77
77
|
await client.cacheDataSet({ endpoint: resource.url(item.path), value: item.value, version: item.sha256 })
|
|
78
78
|
next[item.key] = item
|
|
79
79
|
})
|
|
80
|
+
await onResources?.()
|
|
80
81
|
|
|
81
82
|
const pictures = changed.filter(item => item.kind === 'image')
|
|
82
83
|
await this.queue(pictures, images.concurrency, async item => {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0.
|
|
2
|
+
"version": "2.0.3",
|
|
3
3
|
"name": "@fullstackunicorn/webapp",
|
|
4
4
|
"author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
|
|
5
5
|
"description": "Shared Web and Native runtime engines and core components for Fullstack Unicorn applications",
|
package/package.md
CHANGED
|
@@ -14,7 +14,9 @@ initial image sizes through the host's `load/geometry.scope.js`. Before reportin
|
|
|
14
14
|
an inventory as complete, it verifies that every declared JSON resource and image
|
|
15
15
|
binary is actually present at the declared version in browser cache. Hosts may use
|
|
16
16
|
the `Load` component's `onReady` callback to initialize page content only after
|
|
17
|
-
|
|
17
|
+
the required JSON resources have been reconciled. Image warming continues in
|
|
18
|
+
parallel and shares the same requests and cache with mounted `Img` components.
|
|
19
|
+
The shared
|
|
18
20
|
`Img` component measures its mounted container, treats `src + hash` as binary
|
|
19
21
|
identity and keeps the decoded displayed image visible until a changed pending
|
|
20
22
|
binary has decoded and cross-faded.
|