source: trip-planner-front/node_modules/webpack-dev-server/client/utils/reloadApp.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[6a3a178]1'use strict';
2/* global WorkerGlobalScope self */
3
4var _require = require('./log'),
5 log = _require.log;
6
7function reloadApp(_ref, _ref2) {
8 var hotReload = _ref.hotReload,
9 hot = _ref.hot,
10 liveReload = _ref.liveReload;
11 var isUnloading = _ref2.isUnloading,
12 currentHash = _ref2.currentHash;
13
14 if (isUnloading || !hotReload) {
15 return;
16 }
17
18 if (hot) {
19 log.info('[WDS] App hot update...');
20
21 var hotEmitter = require('webpack/hot/emitter');
22
23 hotEmitter.emit('webpackHotUpdate', currentHash);
24
25 if (typeof self !== 'undefined' && self.window) {
26 // broadcast update to window
27 self.postMessage("webpackHotUpdate".concat(currentHash), '*');
28 }
29 } // allow refreshing the page only if liveReload isn't disabled
30 else if (liveReload) {
31 var rootWindow = self; // use parent window for reload (in case we're in an iframe with no valid src)
32
33 var intervalId = self.setInterval(function () {
34 if (rootWindow.location.protocol !== 'about:') {
35 // reload immediately if protocol is valid
36 applyReload(rootWindow, intervalId);
37 } else {
38 rootWindow = rootWindow.parent;
39
40 if (rootWindow.parent === rootWindow) {
41 // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
42 applyReload(rootWindow, intervalId);
43 }
44 }
45 });
46 }
47
48 function applyReload(rootWindow, intervalId) {
49 clearInterval(intervalId);
50 log.info('[WDS] App updated. Reloading...');
51 rootWindow.location.reload();
52 }
53}
54
55module.exports = reloadApp;
Note: See TracBrowser for help on using the repository browser.