@jsenv/core 39.5.26 → 39.6.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/dist/js/autoreload.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseSrcSet, stringifySrcSet } from "@jsenv/ast/src/html/html_src_set.js";
|
|
2
|
-
import { urlHotMetas } from "./import_meta_hot.js";
|
|
2
|
+
import { urlHotMetas, dispatchBeforeFullReload, dispatchBeforePartialReload, dispatchAfterPartialReload, dispatchBeforePrune } from "./import_meta_hot.js";
|
|
3
3
|
|
|
4
4
|
const initAutoreload = ({ mainFilePath }) => {
|
|
5
5
|
const reloader = {
|
|
@@ -55,9 +55,11 @@ const initAutoreload = ({ mainFilePath }) => {
|
|
|
55
55
|
(reloadMessage) => reloadMessage.type === "full",
|
|
56
56
|
);
|
|
57
57
|
if (someEffectIsFullReload) {
|
|
58
|
+
dispatchBeforeFullReload();
|
|
58
59
|
reloadHtmlPage();
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
62
|
+
dispatchBeforePartialReload();
|
|
61
63
|
reloader.status.goTo("reloading");
|
|
62
64
|
const onApplied = (reloadMessage) => {
|
|
63
65
|
reloader.changes.remove(reloadMessage);
|
|
@@ -67,6 +69,7 @@ const initAutoreload = ({ mainFilePath }) => {
|
|
|
67
69
|
() => {
|
|
68
70
|
onApplied(reloadMessage);
|
|
69
71
|
reloader.currentExecution = null;
|
|
72
|
+
dispatchAfterPartialReload();
|
|
70
73
|
},
|
|
71
74
|
(e) => {
|
|
72
75
|
reloader.status.goTo("failed");
|
|
@@ -134,6 +137,7 @@ This could be due to syntax errors or importing non-existent modules (see errors
|
|
|
134
137
|
// - import.meta.hot.accept() is not called (happens for HTML and CSS)
|
|
135
138
|
if (type === "prune") {
|
|
136
139
|
if (urlHotMeta) {
|
|
140
|
+
dispatchBeforePrune();
|
|
137
141
|
delete urlHotMetas[urlToFetch];
|
|
138
142
|
if (urlHotMeta.disposeCallback) {
|
|
139
143
|
console.groupCollapsed(
|
|
@@ -5,12 +5,40 @@
|
|
|
5
5
|
|
|
6
6
|
const urlHotMetas = {};
|
|
7
7
|
|
|
8
|
+
const createEvent = () => {
|
|
9
|
+
const callbackSet = new Set();
|
|
10
|
+
const addCallback = (callback) => {
|
|
11
|
+
callbackSet.add(callback);
|
|
12
|
+
return () => {
|
|
13
|
+
callbackSet.delete(callback);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const dispatch = () => {
|
|
17
|
+
for (const callback of callbackSet) {
|
|
18
|
+
callback();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return [{ addCallback }, dispatch];
|
|
22
|
+
};
|
|
23
|
+
const [beforePartialReload, dispatchBeforePartialReload] = createEvent();
|
|
24
|
+
const [afterPartialReload, dispatchAfterPartialReload] = createEvent();
|
|
25
|
+
const [beforeFullReload, dispatchBeforeFullReload] = createEvent();
|
|
26
|
+
const [beforePrune, dispatchBeforePrune] = createEvent();
|
|
27
|
+
|
|
28
|
+
const hotEvents = {
|
|
29
|
+
beforePartialReload,
|
|
30
|
+
afterPartialReload,
|
|
31
|
+
beforeFullReload,
|
|
32
|
+
beforePrune,
|
|
33
|
+
};
|
|
34
|
+
|
|
8
35
|
const createImportMetaHot = (importMetaUrl) => {
|
|
9
36
|
const data = {};
|
|
10
37
|
const url = asUrlWithoutHotSearchParam(importMetaUrl);
|
|
11
38
|
|
|
12
39
|
return {
|
|
13
40
|
data,
|
|
41
|
+
events: hotEvents,
|
|
14
42
|
accept: (firstArg, secondArg) => {
|
|
15
43
|
if (!firstArg) {
|
|
16
44
|
addUrlMeta(url, {
|
|
@@ -80,4 +108,4 @@ const asUrlWithoutHotSearchParam = (url) => {
|
|
|
80
108
|
return url;
|
|
81
109
|
};
|
|
82
110
|
|
|
83
|
-
export { createImportMetaHot, urlHotMetas };
|
|
111
|
+
export { createImportMetaHot, dispatchAfterPartialReload, dispatchBeforeFullReload, dispatchBeforePartialReload, dispatchBeforePrune, urlHotMetas };
|
package/package.json
CHANGED
|
@@ -2,7 +2,13 @@ import {
|
|
|
2
2
|
parseSrcSet,
|
|
3
3
|
stringifySrcSet,
|
|
4
4
|
} from "@jsenv/ast/src/html/html_src_set.js";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
dispatchAfterPartialReload,
|
|
7
|
+
dispatchBeforeFullReload,
|
|
8
|
+
dispatchBeforePartialReload,
|
|
9
|
+
dispatchBeforePrune,
|
|
10
|
+
urlHotMetas,
|
|
11
|
+
} from "../../import_meta_hot/client/import_meta_hot.js";
|
|
6
12
|
|
|
7
13
|
export const initAutoreload = ({ mainFilePath }) => {
|
|
8
14
|
let debug = false;
|
|
@@ -62,9 +68,11 @@ export const initAutoreload = ({ mainFilePath }) => {
|
|
|
62
68
|
(reloadMessage) => reloadMessage.type === "full",
|
|
63
69
|
);
|
|
64
70
|
if (someEffectIsFullReload) {
|
|
71
|
+
dispatchBeforeFullReload();
|
|
65
72
|
reloadHtmlPage();
|
|
66
73
|
return;
|
|
67
74
|
}
|
|
75
|
+
dispatchBeforePartialReload();
|
|
68
76
|
reloader.status.goTo("reloading");
|
|
69
77
|
const onApplied = (reloadMessage) => {
|
|
70
78
|
reloader.changes.remove(reloadMessage);
|
|
@@ -74,6 +82,7 @@ export const initAutoreload = ({ mainFilePath }) => {
|
|
|
74
82
|
() => {
|
|
75
83
|
onApplied(reloadMessage);
|
|
76
84
|
reloader.currentExecution = null;
|
|
85
|
+
dispatchAfterPartialReload();
|
|
77
86
|
},
|
|
78
87
|
(e) => {
|
|
79
88
|
reloader.status.goTo("failed");
|
|
@@ -141,6 +150,7 @@ This could be due to syntax errors or importing non-existent modules (see errors
|
|
|
141
150
|
// - import.meta.hot.accept() is not called (happens for HTML and CSS)
|
|
142
151
|
if (type === "prune") {
|
|
143
152
|
if (urlHotMeta) {
|
|
153
|
+
dispatchBeforePrune();
|
|
144
154
|
delete urlHotMetas[urlToFetch];
|
|
145
155
|
if (urlHotMeta.disposeCallback) {
|
|
146
156
|
console.groupCollapsed(
|
|
@@ -5,12 +5,46 @@
|
|
|
5
5
|
|
|
6
6
|
export const urlHotMetas = {};
|
|
7
7
|
|
|
8
|
+
const createEvent = () => {
|
|
9
|
+
const callbackSet = new Set();
|
|
10
|
+
const addCallback = (callback) => {
|
|
11
|
+
callbackSet.add(callback);
|
|
12
|
+
return () => {
|
|
13
|
+
callbackSet.delete(callback);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const dispatch = () => {
|
|
17
|
+
for (const callback of callbackSet) {
|
|
18
|
+
callback();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return [{ addCallback }, dispatch];
|
|
22
|
+
};
|
|
23
|
+
const [beforePartialReload, dispatchBeforePartialReload] = createEvent();
|
|
24
|
+
const [afterPartialReload, dispatchAfterPartialReload] = createEvent();
|
|
25
|
+
const [beforeFullReload, dispatchBeforeFullReload] = createEvent();
|
|
26
|
+
const [beforePrune, dispatchBeforePrune] = createEvent();
|
|
27
|
+
export {
|
|
28
|
+
dispatchAfterPartialReload,
|
|
29
|
+
dispatchBeforeFullReload,
|
|
30
|
+
dispatchBeforePartialReload,
|
|
31
|
+
dispatchBeforePrune,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const hotEvents = {
|
|
35
|
+
beforePartialReload,
|
|
36
|
+
afterPartialReload,
|
|
37
|
+
beforeFullReload,
|
|
38
|
+
beforePrune,
|
|
39
|
+
};
|
|
40
|
+
|
|
8
41
|
export const createImportMetaHot = (importMetaUrl) => {
|
|
9
42
|
const data = {};
|
|
10
43
|
const url = asUrlWithoutHotSearchParam(importMetaUrl);
|
|
11
44
|
|
|
12
45
|
return {
|
|
13
46
|
data,
|
|
47
|
+
events: hotEvents,
|
|
14
48
|
accept: (firstArg, secondArg) => {
|
|
15
49
|
if (!firstArg) {
|
|
16
50
|
addUrlMeta(url, {
|