@inglorious/web 4.1.4 → 4.1.6
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 +2 -2
- package/src/mount.js +11 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/web",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.6",
|
|
4
4
|
"description": "A new web framework that leverages the power of the Inglorious Store combined with the performance and simplicity of lit-html.",
|
|
5
5
|
"author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@lit-labs/ssr-client": "^1.1.8",
|
|
70
70
|
"lit-html": "^3.3.1",
|
|
71
|
-
"@inglorious/store": "9.
|
|
71
|
+
"@inglorious/store": "9.4.0",
|
|
72
72
|
"@inglorious/utils": "3.7.3"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
package/src/mount.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { hydrate } from "@lit-labs/ssr-client"
|
|
2
1
|
import { html, render } from "lit-html"
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -8,25 +7,27 @@ import { html, render } from "lit-html"
|
|
|
8
7
|
* @param {HTMLElement | DocumentFragment} element - The DOM element to mount the template to.
|
|
9
8
|
* @returns {() => void} An unsubscribe function
|
|
10
9
|
*/
|
|
11
|
-
export function mount(store, renderFn, element) {
|
|
10
|
+
export async function mount(store, renderFn, element) {
|
|
12
11
|
const api = { ...store._api }
|
|
13
12
|
api.render = createRender(api)
|
|
14
13
|
|
|
15
14
|
let shouldHydrate = element.hasChildNodes()
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
// If we need to hydrate, load the heavy lifting only now
|
|
17
|
+
if (shouldHydrate) {
|
|
18
|
+
const { hydrate } = await import("@lit-labs/ssr-client")
|
|
18
19
|
const template = renderFn(api)
|
|
20
|
+
hydrate(template, element)
|
|
21
|
+
shouldHydrate = false
|
|
22
|
+
}
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
render(template, element)
|
|
25
|
-
}
|
|
24
|
+
const unsubscribe = store.subscribe(() => {
|
|
25
|
+
const template = renderFn(api)
|
|
26
|
+
// Standard render is already in the main bundle (it's small)
|
|
27
|
+
render(template, element)
|
|
26
28
|
})
|
|
27
29
|
|
|
28
30
|
store.notify("init")
|
|
29
|
-
|
|
30
31
|
return unsubscribe
|
|
31
32
|
}
|
|
32
33
|
|