2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
8 var $interceptModuleExecution$ = undefined;
9 var $moduleCache$ = undefined;
10 // eslint-disable-next-line no-unused-vars
11 var $hmrModuleData$ = undefined;
12 /** @type {() => Promise} */
13 var $hmrDownloadManifest$ = undefined;
14 var $hmrDownloadUpdateHandlers$ = undefined;
15 var $hmrInvalidateModuleHandlers$ = undefined;
16 var __webpack_require__ = undefined;
18 module.exports = function () {
19 var currentModuleData = {};
20 var installedModules = $moduleCache$;
22 // module and require creation
23 var currentChildModule;
24 var currentParents = [];
27 var registeredStatusHandlers = [];
28 var currentStatus = "idle";
31 var blockingPromises = 0;
32 var blockingPromisesWaiting = [];
35 var currentUpdateApplyHandlers;
36 var queuedInvalidatedModules;
38 // eslint-disable-next-line no-unused-vars
39 $hmrModuleData$ = currentModuleData;
41 $interceptModuleExecution$.push(function (options) {
42 var module = options.module;
43 var require = createRequire(options.require, options.id);
44 module.hot = createModuleHotObject(options.id, module);
45 module.parents = currentParents;
48 options.require = require;
51 $hmrDownloadUpdateHandlers$ = {};
52 $hmrInvalidateModuleHandlers$ = {};
54 function createRequire(require, moduleId) {
55 var me = installedModules[moduleId];
56 if (!me) return require;
57 var fn = function (request) {
59 if (installedModules[request]) {
60 var parents = installedModules[request].parents;
61 if (parents.indexOf(moduleId) === -1) {
62 parents.push(moduleId);
65 currentParents = [moduleId];
66 currentChildModule = request;
68 if (me.children.indexOf(request) === -1) {
69 me.children.push(request);
73 "[HMR] unexpected require(" +
75 ") from disposed module " +
80 return require(request);
82 var createPropertyDescriptor = function (name) {
89 set: function (value) {
90 require[name] = value;
94 for (var name in require) {
95 if (Object.prototype.hasOwnProperty.call(require, name) && name !== "e") {
96 Object.defineProperty(fn, name, createPropertyDescriptor(name));
99 fn.e = function (chunkId) {
100 return trackBlockingPromise(require.e(chunkId));
105 function createModuleHotObject(moduleId, me) {
106 var _main = currentChildModule !== moduleId;
109 _acceptedDependencies: {},
110 _acceptedErrorHandlers: {},
111 _declinedDependencies: {},
112 _selfAccepted: false,
113 _selfDeclined: false,
114 _selfInvalidated: false,
115 _disposeHandlers: [],
117 _requireSelf: function () {
118 currentParents = me.parents.slice();
119 currentChildModule = _main ? undefined : moduleId;
120 __webpack_require__(moduleId);
125 accept: function (dep, callback, errorHandler) {
126 if (dep === undefined) hot._selfAccepted = true;
127 else if (typeof dep === "function") hot._selfAccepted = dep;
128 else if (typeof dep === "object" && dep !== null) {
129 for (var i = 0; i < dep.length; i++) {
130 hot._acceptedDependencies[dep[i]] = callback || function () {};
131 hot._acceptedErrorHandlers[dep[i]] = errorHandler;
134 hot._acceptedDependencies[dep] = callback || function () {};
135 hot._acceptedErrorHandlers[dep] = errorHandler;
138 decline: function (dep) {
139 if (dep === undefined) hot._selfDeclined = true;
140 else if (typeof dep === "object" && dep !== null)
141 for (var i = 0; i < dep.length; i++)
142 hot._declinedDependencies[dep[i]] = true;
143 else hot._declinedDependencies[dep] = true;
145 dispose: function (callback) {
146 hot._disposeHandlers.push(callback);
148 addDisposeHandler: function (callback) {
149 hot._disposeHandlers.push(callback);
151 removeDisposeHandler: function (callback) {
152 var idx = hot._disposeHandlers.indexOf(callback);
153 if (idx >= 0) hot._disposeHandlers.splice(idx, 1);
155 invalidate: function () {
156 this._selfInvalidated = true;
157 switch (currentStatus) {
159 currentUpdateApplyHandlers = [];
160 Object.keys($hmrInvalidateModuleHandlers$).forEach(function (key) {
161 $hmrInvalidateModuleHandlers$[key](
163 currentUpdateApplyHandlers
169 Object.keys($hmrInvalidateModuleHandlers$).forEach(function (key) {
170 $hmrInvalidateModuleHandlers$[key](
172 currentUpdateApplyHandlers
180 (queuedInvalidatedModules = queuedInvalidatedModules || []).push(
185 // ignore requests in error states
193 status: function (l) {
194 if (!l) return currentStatus;
195 registeredStatusHandlers.push(l);
197 addStatusHandler: function (l) {
198 registeredStatusHandlers.push(l);
200 removeStatusHandler: function (l) {
201 var idx = registeredStatusHandlers.indexOf(l);
202 if (idx >= 0) registeredStatusHandlers.splice(idx, 1);
205 //inherit from previous dispose call
206 data: currentModuleData[moduleId]
208 currentChildModule = undefined;
212 function setStatus(newStatus) {
213 currentStatus = newStatus;
216 for (var i = 0; i < registeredStatusHandlers.length; i++)
217 results[i] = registeredStatusHandlers[i].call(null, newStatus);
219 return Promise.all(results);
223 if (--blockingPromises === 0) {
224 setStatus("ready").then(function () {
225 if (blockingPromises === 0) {
226 var list = blockingPromisesWaiting;
227 blockingPromisesWaiting = [];
228 for (var i = 0; i < list.length; i++) {
236 function trackBlockingPromise(promise) {
237 switch (currentStatus) {
239 setStatus("prepare");
243 promise.then(unblock, unblock);
250 function waitForBlockingPromises(fn) {
251 if (blockingPromises === 0) return fn();
252 return new Promise(function (resolve) {
253 blockingPromisesWaiting.push(function () {
259 function hotCheck(applyOnUpdate) {
260 if (currentStatus !== "idle") {
261 throw new Error("check() is only allowed in idle status");
263 return setStatus("check")
264 .then($hmrDownloadManifest$)
265 .then(function (update) {
267 return setStatus(applyInvalidatedModules() ? "ready" : "idle").then(
274 return setStatus("prepare").then(function () {
275 var updatedModules = [];
276 currentUpdateApplyHandlers = [];
279 Object.keys($hmrDownloadUpdateHandlers$).reduce(function (
283 $hmrDownloadUpdateHandlers$[key](
288 currentUpdateApplyHandlers,
295 return waitForBlockingPromises(function () {
297 return internalApply(applyOnUpdate);
299 return setStatus("ready").then(function () {
300 return updatedModules;
309 function hotApply(options) {
310 if (currentStatus !== "ready") {
311 return Promise.resolve().then(function () {
313 "apply() is only allowed in ready status (state: " +
319 return internalApply(options);
322 function internalApply(options) {
323 options = options || {};
325 applyInvalidatedModules();
327 var results = currentUpdateApplyHandlers.map(function (handler) {
328 return handler(options);
330 currentUpdateApplyHandlers = undefined;
338 if (errors.length > 0) {
339 return setStatus("abort").then(function () {
344 // Now in "dispose" phase
345 var disposePromise = setStatus("dispose");
347 results.forEach(function (result) {
348 if (result.dispose) result.dispose();
351 // Now in "apply" phase
352 var applyPromise = setStatus("apply");
355 var reportError = function (err) {
356 if (!error) error = err;
359 var outdatedModules = [];
360 results.forEach(function (result) {
362 var modules = result.apply(reportError);
364 for (var i = 0; i < modules.length; i++) {
365 outdatedModules.push(modules[i]);
371 return Promise.all([disposePromise, applyPromise]).then(function () {
372 // handle errors in accept handlers and self accepted module load
374 return setStatus("fail").then(function () {
379 if (queuedInvalidatedModules) {
380 return internalApply(options).then(function (list) {
381 outdatedModules.forEach(function (moduleId) {
382 if (list.indexOf(moduleId) < 0) list.push(moduleId);
388 return setStatus("idle").then(function () {
389 return outdatedModules;
394 function applyInvalidatedModules() {
395 if (queuedInvalidatedModules) {
396 if (!currentUpdateApplyHandlers) currentUpdateApplyHandlers = [];
397 Object.keys($hmrInvalidateModuleHandlers$).forEach(function (key) {
398 queuedInvalidatedModules.forEach(function (moduleId) {
399 $hmrInvalidateModuleHandlers$[key](
401 currentUpdateApplyHandlers
405 queuedInvalidatedModules = undefined;