Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 87f6f19

Browse files
authored
fix-next(Angular): HMR for lazy loaded NgModules (#759)
* fix-next(Angular): HMR for lazy loaded NgModules Currently, the `lazy-ngmodule-hot-loader` [adds](6a9db32) a HMR self-accept to every lazy loaded NgModule during build. After [alignment](fe4abfb) of the HMR lifecycle of NativeScript Angular with non-Angular applications, it requires a handler to update the app after module replacement. * refactor: minor tweaks * Apply suggestions from code review Co-Authored-By: vchimev <vasil.chimev@gmail.com>
1 parent 0c35c8b commit 87f6f19

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎lazy-ngmodule-hot-loader.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
const { safeGet } = require("./projectHelpers");
22

33
const LAZY_RESOURCE_CONTEXT = "$$_lazy_route_resource";
4-
const HOT_SELF_ACCEPT = "module.hot && module.hot.accept()";
4+
const HOT_SELF_ACCEPT = "module.hot.accept();";
5+
const HOT_DISPOSE = `
6+
module.hot.dispose(() => {
7+
// Currently the context is needed only for application style modules.
8+
const moduleContext = "{}";
9+
global.__hmrRefresh(moduleContext);
10+
});
11+
`;
12+
const HMR_HANDLER = `
13+
if (module.hot) {
14+
${HOT_SELF_ACCEPT}
15+
${HOT_DISPOSE}
16+
}
17+
`;
518

619
const isLazyLoadedNgModule = resource => {
720
const issuer = safeGet(resource, "issuer");
@@ -12,6 +25,6 @@ const isLazyLoadedNgModule = resource => {
1225

1326
module.exports = function (source) {
1427
return isLazyLoadedNgModule(this._module) ?
15-
`${source};${HOT_SELF_ACCEPT}`:
28+
`${source};${HMR_HANDLER}`:
1629
source;
1730
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /