From 911428b628609417b1eb203736be791d5bda88c4 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Thu, 10 Jan 2019 13:00:52 +0200 Subject: [PATCH 1/2] refactor(HMR): rename global.__hmrRefresh function --- bundle-config-loader.js | 4 ++-- demo/AngularApp/app/main.ts | 2 +- hot-loader-helper.js | 2 +- lazy-ngmodule-hot-loader.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bundle-config-loader.js b/bundle-config-loader.js index 3c489b4b..0541e95f 100644 --- a/bundle-config-loader.js +++ b/bundle-config-loader.js @@ -12,7 +12,7 @@ module.exports = function (source) { hmrUpdate(); }; - global.__hmrRefresh = function({ type, module } = {}) { + global.hmrRefresh = function({ type, module } = {}) { if (initialHmrUpdate) { return; } @@ -22,7 +22,7 @@ module.exports = function (source) { }); }; - hmrUpdate().then(() =>{ + hmrUpdate().then(() => { initialHmrUpdate = false; }) } diff --git a/demo/AngularApp/app/main.ts b/demo/AngularApp/app/main.ts index eea29eb0..753b2683 100644 --- a/demo/AngularApp/app/main.ts +++ b/demo/AngularApp/app/main.ts @@ -17,7 +17,7 @@ if (module["hot"]) { module["hot"].accept(["./app.module"], () => { // Currently the context is needed only for application style modules. const moduleContext = {}; - global["__hmrRefresh"](moduleContext); + global["hmrRefresh"](moduleContext); }); } diff --git a/hot-loader-helper.js b/hot-loader-helper.js index 49dd51d5..d69a8848 100644 --- a/hot-loader-helper.js +++ b/hot-loader-helper.js @@ -3,7 +3,7 @@ module.exports.reload = function ({ type, module }) { if (module.hot) { module.hot.accept(); module.hot.dispose(() => { - global.__hmrRefresh({ type: '${type}', module: '${module}' }); + global.hmrRefresh({ type: '${type}', module: '${module}' }); }) } `}; diff --git a/lazy-ngmodule-hot-loader.js b/lazy-ngmodule-hot-loader.js index 1384f744..054602a3 100644 --- a/lazy-ngmodule-hot-loader.js +++ b/lazy-ngmodule-hot-loader.js @@ -6,7 +6,7 @@ const HOT_DISPOSE = ` module.hot.dispose(() => { // Currently the context is needed only for application style modules. const moduleContext = {}; - global.__hmrRefresh(moduleContext); + global.hmrRefresh(moduleContext); });`; const HMR_HANDLER = ` if (module.hot) { From bb31af53e120871b7c27be196796b9438a5f0e77 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Thu, 10 Jan 2019 13:27:12 +0200 Subject: [PATCH 2/2] refactor(HMR): add __initialHmrUpdate to global scope --- bundle-config-loader.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundle-config-loader.js b/bundle-config-loader.js index 0541e95f..0b396ff9 100644 --- a/bundle-config-loader.js +++ b/bundle-config-loader.js @@ -5,7 +5,7 @@ module.exports = function (source) { const hmr = ` if (module.hot) { const hmrUpdate = require("nativescript-dev-webpack/hmr").hmrUpdate; - let initialHmrUpdate = true; + global.__initialHmrUpdate = true; global.__hmrSyncBackup = global.__onLiveSync; global.__onLiveSync = function () { @@ -13,7 +13,7 @@ module.exports = function (source) { }; global.hmrRefresh = function({ type, module } = {}) { - if (initialHmrUpdate) { + if (global.__initialHmrUpdate) { return; } @@ -23,7 +23,7 @@ module.exports = function (source) { }; hmrUpdate().then(() => { - initialHmrUpdate = false; + global.__initialHmrUpdate = false; }) } `;