source: frontend/node_modules/webpack/hot/lazy-compilation-web.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[9af201e]1"use strict";
2
3/* global __resourceQuery */
4
5if (typeof EventSource !== "function") {
6 throw new Error(
7 "Environment doesn't support lazy compilation (requires EventSource)"
8 );
9}
10
11var urlBase = decodeURIComponent(__resourceQuery.slice(1));
12/** @type {EventSource | undefined} */
13var activeEventSource;
14var activeKeys = new Map();
15var errorHandlers = new Set();
16
17var updateEventSource = function updateEventSource() {
18 if (activeEventSource) activeEventSource.close();
19 if (activeKeys.size) {
20 activeEventSource = new EventSource(
21 urlBase + Array.from(activeKeys.keys()).join("@")
22 );
23 /**
24 * @this {EventSource}
25 * @param {Event & { message?: string, filename?: string, lineno?: number, colno?: number, error?: Error }} event event
26 */
27 activeEventSource.onerror = function (event) {
28 errorHandlers.forEach(function (onError) {
29 onError(
30 new Error(
31 "Problem communicating active modules to the server: " +
32 event.message +
33 " " +
34 event.filename +
35 ":" +
36 event.lineno +
37 ":" +
38 event.colno +
39 " " +
40 event.error
41 )
42 );
43 });
44 };
45 } else {
46 activeEventSource = undefined;
47 }
48};
49
50/**
51 * @param {{ data: string, onError: (err: Error) => void, active: boolean, module: module }} options options
52 * @returns {() => void} function to destroy response
53 */
54exports.keepAlive = function (options) {
55 var data = options.data;
56 var onError = options.onError;
57
58 errorHandlers.add(onError);
59
60 var value = activeKeys.get(data) || 0;
61
62 activeKeys.set(data, value + 1);
63
64 if (value === 0) {
65 updateEventSource();
66 }
67
68 if (!options.active && !options.module.hot) {
69 console.log(
70 "Hot Module Replacement is not enabled. Waiting for process restart..."
71 );
72 }
73
74 return function () {
75 errorHandlers.delete(onError);
76 setTimeout(function () {
77 var value = activeKeys.get(data);
78 if (value === 1) {
79 activeKeys.delete(data);
80 updateEventSource();
81 } else {
82 activeKeys.set(data, value - 1);
83 }
84 }, 1000);
85 };
86};
87
88/**
89 * @param {string} value new url value
90 */
91exports.setUrl = function (value) {
92 urlBase = value;
93};
Note: See TracBrowser for help on using the repository browser.