@inglorious/web 6.14.1 → 6.15.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": "@inglorious/web",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.15.0",
|
|
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": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"contributors": [
|
|
@@ -4,6 +4,7 @@ const DEFAULT_DELAY = 300
|
|
|
4
4
|
|
|
5
5
|
const reloads = new Set()
|
|
6
6
|
let isWatchingVisibility = false
|
|
7
|
+
let isWatchingConnection = false
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Keeps an entity in step with a backend: whenever one of the `tables` it
|
|
@@ -23,9 +24,10 @@ let isWatchingVisibility = false
|
|
|
23
24
|
* always.
|
|
24
25
|
* - `delay` (default 300 ms) gathers a burst of changes into one reload.
|
|
25
26
|
*
|
|
26
|
-
* It also reloads every live entity when the page comes back into view
|
|
27
|
-
* phone that put the app in the
|
|
28
|
-
*
|
|
27
|
+
* It also reloads every live entity when the page comes back into view, and
|
|
28
|
+
* when the browser comes back online: a phone that put the app in the
|
|
29
|
+
* background, or lost its signal, may have dropped the connection, and the
|
|
30
|
+
* changes with it.
|
|
29
31
|
*
|
|
30
32
|
* IMPORTANT: changes arrive long after the handler that subscribed has
|
|
31
33
|
* returned, when its `entity` draft is revoked. So only the entity's `id` is
|
|
@@ -90,6 +92,7 @@ export function withLiveReload({
|
|
|
90
92
|
})
|
|
91
93
|
reloads.add(reload)
|
|
92
94
|
watchVisibility()
|
|
95
|
+
watchConnection()
|
|
93
96
|
},
|
|
94
97
|
|
|
95
98
|
destroy(entity, destroyPayload, api) {
|
|
@@ -105,6 +108,16 @@ function watchVisibility() {
|
|
|
105
108
|
isWatchingVisibility = true
|
|
106
109
|
document.addEventListener("visibilitychange", () => {
|
|
107
110
|
if (document.visibilityState !== "visible") return
|
|
108
|
-
|
|
111
|
+
reloadAll()
|
|
109
112
|
})
|
|
110
113
|
}
|
|
114
|
+
|
|
115
|
+
function watchConnection() {
|
|
116
|
+
if (isWatchingConnection || typeof window === "undefined") return
|
|
117
|
+
isWatchingConnection = true
|
|
118
|
+
window.addEventListener("online", reloadAll)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function reloadAll() {
|
|
122
|
+
reloads.forEach((reload) => reload())
|
|
123
|
+
}
|