@ngxs/hmr-plugin 3.8.2 → 18.0.0-dev.master-f4c2c19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/{esm2015/src/actions/hmr-before-destroy.action.js → esm2022/src/actions/hmr-before-destroy.action.mjs} +4 -4
  2. package/{esm2015/src/actions/hmr-init.action.js → esm2022/src/actions/hmr-init.action.mjs} +4 -4
  3. package/esm2022/src/hmr-bootstrap.mjs +28 -0
  4. package/esm2022/src/hmr-manager.mjs +73 -0
  5. package/esm2022/src/internal/hmr-lifecycle.mjs +66 -0
  6. package/{esm2015/src/internal/hmr-options-builder.js → esm2022/src/internal/hmr-options-builder.mjs} +1 -1
  7. package/esm2022/src/internal/hmr-state-context-factory.mjs +36 -0
  8. package/{esm2015/src/utils/externals.js → esm2022/src/utils/externals.mjs} +2 -2
  9. package/esm2022/src/utils/internals.mjs +11 -0
  10. package/{fesm2015/ngxs-hmr-plugin.js → fesm2022/ngxs-hmr-plugin.mjs} +44 -50
  11. package/fesm2022/ngxs-hmr-plugin.mjs.map +1 -0
  12. package/package.json +17 -11
  13. package/src/hmr-manager.d.ts +1 -1
  14. package/src/internal/hmr-lifecycle.d.ts +3 -3
  15. package/src/symbols.d.ts +4 -4
  16. package/bundles/ngxs-hmr-plugin.umd.js +0 -790
  17. package/bundles/ngxs-hmr-plugin.umd.js.map +0 -1
  18. package/esm2015/src/hmr-bootstrap.js +0 -31
  19. package/esm2015/src/hmr-manager.js +0 -76
  20. package/esm2015/src/internal/hmr-lifecycle.js +0 -67
  21. package/esm2015/src/internal/hmr-state-context-factory.js +0 -36
  22. package/esm2015/src/utils/internals.js +0 -11
  23. package/fesm2015/ngxs-hmr-plugin.js.map +0 -1
  24. package/ngxs-hmr-plugin.d.ts +0 -5
  25. /package/{esm2015/index.js → esm2022/index.mjs} +0 -0
  26. /package/{esm2015/ngxs-hmr-plugin.js → esm2022/ngxs-hmr-plugin.mjs} +0 -0
  27. /package/{esm2015/src/internal/hmr-storage.js → esm2022/src/internal/hmr-storage.mjs} +0 -0
  28. /package/{esm2015/src/public_api.js → esm2022/src/public_api.mjs} +0 -0
  29. /package/{esm2015/src/symbols.js → esm2022/src/symbols.mjs} +0 -0
@@ -1,790 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@ngxs/store/internals'), require('@ngxs/store'), require('@ngxs/store/operators')) :
3
- typeof define === 'function' && define.amd ? define('@ngxs/hmr-plugin', ['exports', '@angular/core', '@ngxs/store/internals', '@ngxs/store', '@ngxs/store/operators'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ngxs = global.ngxs || {}, global.ngxs["hmr-plugin"] = {}), global.ng.core, global["ngxs-store-internals"], global["ngxs-store"], global["ngxs-store-operators"]));
5
- })(this, (function (exports, core, internals, store, operators) { 'use strict';
6
-
7
- var HmrInitAction = /** @class */ (function () {
8
- function HmrInitAction(payload) {
9
- this.payload = payload;
10
- }
11
- Object.defineProperty(HmrInitAction, "type", {
12
- get: function () {
13
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
14
- return '@@HMR_INIT';
15
- },
16
- enumerable: false,
17
- configurable: true
18
- });
19
- return HmrInitAction;
20
- }());
21
-
22
- var HmrBeforeDestroyAction = /** @class */ (function () {
23
- function HmrBeforeDestroyAction(payload) {
24
- this.payload = payload;
25
- }
26
- Object.defineProperty(HmrBeforeDestroyAction, "type", {
27
- get: function () {
28
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
29
- return '@@HMR_BEFORE_DESTROY';
30
- },
31
- enumerable: false,
32
- configurable: true
33
- });
34
- return HmrBeforeDestroyAction;
35
- }());
36
-
37
- /******************************************************************************
38
- Copyright (c) Microsoft Corporation.
39
-
40
- Permission to use, copy, modify, and/or distribute this software for any
41
- purpose with or without fee is hereby granted.
42
-
43
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
44
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
45
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
46
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
47
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
48
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
49
- PERFORMANCE OF THIS SOFTWARE.
50
- ***************************************************************************** */
51
- /* global Reflect, Promise, SuppressedError, Symbol */
52
- var extendStatics = function (d, b) {
53
- extendStatics = Object.setPrototypeOf ||
54
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
55
- function (d, b) { for (var p in b)
56
- if (Object.prototype.hasOwnProperty.call(b, p))
57
- d[p] = b[p]; };
58
- return extendStatics(d, b);
59
- };
60
- function __extends(d, b) {
61
- if (typeof b !== "function" && b !== null)
62
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
63
- extendStatics(d, b);
64
- function __() { this.constructor = d; }
65
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
66
- }
67
- var __assign = function () {
68
- __assign = Object.assign || function __assign(t) {
69
- for (var s, i = 1, n = arguments.length; i < n; i++) {
70
- s = arguments[i];
71
- for (var p in s)
72
- if (Object.prototype.hasOwnProperty.call(s, p))
73
- t[p] = s[p];
74
- }
75
- return t;
76
- };
77
- return __assign.apply(this, arguments);
78
- };
79
- function __rest(s, e) {
80
- var t = {};
81
- for (var p in s)
82
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
83
- t[p] = s[p];
84
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
85
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
86
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
87
- t[p[i]] = s[p[i]];
88
- }
89
- return t;
90
- }
91
- function __decorate(decorators, target, key, desc) {
92
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
93
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
94
- r = Reflect.decorate(decorators, target, key, desc);
95
- else
96
- for (var i = decorators.length - 1; i >= 0; i--)
97
- if (d = decorators[i])
98
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
99
- return c > 3 && r && Object.defineProperty(target, key, r), r;
100
- }
101
- function __param(paramIndex, decorator) {
102
- return function (target, key) { decorator(target, key, paramIndex); };
103
- }
104
- function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
105
- function accept(f) { if (f !== void 0 && typeof f !== "function")
106
- throw new TypeError("Function expected"); return f; }
107
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
108
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
109
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
110
- var _, done = false;
111
- for (var i = decorators.length - 1; i >= 0; i--) {
112
- var context = {};
113
- for (var p in contextIn)
114
- context[p] = p === "access" ? {} : contextIn[p];
115
- for (var p in contextIn.access)
116
- context.access[p] = contextIn.access[p];
117
- context.addInitializer = function (f) { if (done)
118
- throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
119
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
120
- if (kind === "accessor") {
121
- if (result === void 0)
122
- continue;
123
- if (result === null || typeof result !== "object")
124
- throw new TypeError("Object expected");
125
- if (_ = accept(result.get))
126
- descriptor.get = _;
127
- if (_ = accept(result.set))
128
- descriptor.set = _;
129
- if (_ = accept(result.init))
130
- initializers.unshift(_);
131
- }
132
- else if (_ = accept(result)) {
133
- if (kind === "field")
134
- initializers.unshift(_);
135
- else
136
- descriptor[key] = _;
137
- }
138
- }
139
- if (target)
140
- Object.defineProperty(target, contextIn.name, descriptor);
141
- done = true;
142
- }
143
- ;
144
- function __runInitializers(thisArg, initializers, value) {
145
- var useValue = arguments.length > 2;
146
- for (var i = 0; i < initializers.length; i++) {
147
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
148
- }
149
- return useValue ? value : void 0;
150
- }
151
- ;
152
- function __propKey(x) {
153
- return typeof x === "symbol" ? x : "".concat(x);
154
- }
155
- ;
156
- function __setFunctionName(f, name, prefix) {
157
- if (typeof name === "symbol")
158
- name = name.description ? "[".concat(name.description, "]") : "";
159
- return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
160
- }
161
- ;
162
- function __metadata(metadataKey, metadataValue) {
163
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
164
- return Reflect.metadata(metadataKey, metadataValue);
165
- }
166
- function __awaiter(thisArg, _arguments, P, generator) {
167
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
168
- return new (P || (P = Promise))(function (resolve, reject) {
169
- function fulfilled(value) { try {
170
- step(generator.next(value));
171
- }
172
- catch (e) {
173
- reject(e);
174
- } }
175
- function rejected(value) { try {
176
- step(generator["throw"](value));
177
- }
178
- catch (e) {
179
- reject(e);
180
- } }
181
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
182
- step((generator = generator.apply(thisArg, _arguments || [])).next());
183
- });
184
- }
185
- function __generator(thisArg, body) {
186
- var _ = { label: 0, sent: function () { if (t[0] & 1)
187
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
188
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
189
- function verb(n) { return function (v) { return step([n, v]); }; }
190
- function step(op) {
191
- if (f)
192
- throw new TypeError("Generator is already executing.");
193
- while (g && (g = 0, op[0] && (_ = 0)), _)
194
- try {
195
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
196
- return t;
197
- if (y = 0, t)
198
- op = [op[0] & 2, t.value];
199
- switch (op[0]) {
200
- case 0:
201
- case 1:
202
- t = op;
203
- break;
204
- case 4:
205
- _.label++;
206
- return { value: op[1], done: false };
207
- case 5:
208
- _.label++;
209
- y = op[1];
210
- op = [0];
211
- continue;
212
- case 7:
213
- op = _.ops.pop();
214
- _.trys.pop();
215
- continue;
216
- default:
217
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
218
- _ = 0;
219
- continue;
220
- }
221
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
222
- _.label = op[1];
223
- break;
224
- }
225
- if (op[0] === 6 && _.label < t[1]) {
226
- _.label = t[1];
227
- t = op;
228
- break;
229
- }
230
- if (t && _.label < t[2]) {
231
- _.label = t[2];
232
- _.ops.push(op);
233
- break;
234
- }
235
- if (t[2])
236
- _.ops.pop();
237
- _.trys.pop();
238
- continue;
239
- }
240
- op = body.call(thisArg, _);
241
- }
242
- catch (e) {
243
- op = [6, e];
244
- y = 0;
245
- }
246
- finally {
247
- f = t = 0;
248
- }
249
- if (op[0] & 5)
250
- throw op[1];
251
- return { value: op[0] ? op[1] : void 0, done: true };
252
- }
253
- }
254
- var __createBinding = Object.create ? (function (o, m, k, k2) {
255
- if (k2 === undefined)
256
- k2 = k;
257
- var desc = Object.getOwnPropertyDescriptor(m, k);
258
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
259
- desc = { enumerable: true, get: function () { return m[k]; } };
260
- }
261
- Object.defineProperty(o, k2, desc);
262
- }) : (function (o, m, k, k2) {
263
- if (k2 === undefined)
264
- k2 = k;
265
- o[k2] = m[k];
266
- });
267
- function __exportStar(m, o) {
268
- for (var p in m)
269
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
270
- __createBinding(o, m, p);
271
- }
272
- function __values(o) {
273
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
274
- if (m)
275
- return m.call(o);
276
- if (o && typeof o.length === "number")
277
- return {
278
- next: function () {
279
- if (o && i >= o.length)
280
- o = void 0;
281
- return { value: o && o[i++], done: !o };
282
- }
283
- };
284
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
285
- }
286
- function __read(o, n) {
287
- var m = typeof Symbol === "function" && o[Symbol.iterator];
288
- if (!m)
289
- return o;
290
- var i = m.call(o), r, ar = [], e;
291
- try {
292
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
293
- ar.push(r.value);
294
- }
295
- catch (error) {
296
- e = { error: error };
297
- }
298
- finally {
299
- try {
300
- if (r && !r.done && (m = i["return"]))
301
- m.call(i);
302
- }
303
- finally {
304
- if (e)
305
- throw e.error;
306
- }
307
- }
308
- return ar;
309
- }
310
- /** @deprecated */
311
- function __spread() {
312
- for (var ar = [], i = 0; i < arguments.length; i++)
313
- ar = ar.concat(__read(arguments[i]));
314
- return ar;
315
- }
316
- /** @deprecated */
317
- function __spreadArrays() {
318
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
319
- s += arguments[i].length;
320
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
321
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
322
- r[k] = a[j];
323
- return r;
324
- }
325
- function __spreadArray(to, from, pack) {
326
- if (pack || arguments.length === 2)
327
- for (var i = 0, l = from.length, ar; i < l; i++) {
328
- if (ar || !(i in from)) {
329
- if (!ar)
330
- ar = Array.prototype.slice.call(from, 0, i);
331
- ar[i] = from[i];
332
- }
333
- }
334
- return to.concat(ar || Array.prototype.slice.call(from));
335
- }
336
- function __await(v) {
337
- return this instanceof __await ? (this.v = v, this) : new __await(v);
338
- }
339
- function __asyncGenerator(thisArg, _arguments, generator) {
340
- if (!Symbol.asyncIterator)
341
- throw new TypeError("Symbol.asyncIterator is not defined.");
342
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
343
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
344
- function verb(n) { if (g[n])
345
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
346
- function resume(n, v) { try {
347
- step(g[n](v));
348
- }
349
- catch (e) {
350
- settle(q[0][3], e);
351
- } }
352
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
353
- function fulfill(value) { resume("next", value); }
354
- function reject(value) { resume("throw", value); }
355
- function settle(f, v) { if (f(v), q.shift(), q.length)
356
- resume(q[0][0], q[0][1]); }
357
- }
358
- function __asyncDelegator(o) {
359
- var i, p;
360
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
361
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
362
- }
363
- function __asyncValues(o) {
364
- if (!Symbol.asyncIterator)
365
- throw new TypeError("Symbol.asyncIterator is not defined.");
366
- var m = o[Symbol.asyncIterator], i;
367
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
368
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
369
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
370
- }
371
- function __makeTemplateObject(cooked, raw) {
372
- if (Object.defineProperty) {
373
- Object.defineProperty(cooked, "raw", { value: raw });
374
- }
375
- else {
376
- cooked.raw = raw;
377
- }
378
- return cooked;
379
- }
380
- ;
381
- var __setModuleDefault = Object.create ? (function (o, v) {
382
- Object.defineProperty(o, "default", { enumerable: true, value: v });
383
- }) : function (o, v) {
384
- o["default"] = v;
385
- };
386
- function __importStar(mod) {
387
- if (mod && mod.__esModule)
388
- return mod;
389
- var result = {};
390
- if (mod != null)
391
- for (var k in mod)
392
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
393
- __createBinding(result, mod, k);
394
- __setModuleDefault(result, mod);
395
- return result;
396
- }
397
- function __importDefault(mod) {
398
- return (mod && mod.__esModule) ? mod : { default: mod };
399
- }
400
- function __classPrivateFieldGet(receiver, state, kind, f) {
401
- if (kind === "a" && !f)
402
- throw new TypeError("Private accessor was defined without a getter");
403
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
404
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
405
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
406
- }
407
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
408
- if (kind === "m")
409
- throw new TypeError("Private method is not writable");
410
- if (kind === "a" && !f)
411
- throw new TypeError("Private accessor was defined without a setter");
412
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
413
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
414
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
415
- }
416
- function __classPrivateFieldIn(state, receiver) {
417
- if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
418
- throw new TypeError("Cannot use 'in' operator on non-object");
419
- return typeof state === "function" ? receiver === state : state.has(receiver);
420
- }
421
- function __addDisposableResource(env, value, async) {
422
- if (value !== null && value !== void 0) {
423
- if (typeof value !== "object" && typeof value !== "function")
424
- throw new TypeError("Object expected.");
425
- var dispose;
426
- if (async) {
427
- if (!Symbol.asyncDispose)
428
- throw new TypeError("Symbol.asyncDispose is not defined.");
429
- dispose = value[Symbol.asyncDispose];
430
- }
431
- if (dispose === void 0) {
432
- if (!Symbol.dispose)
433
- throw new TypeError("Symbol.dispose is not defined.");
434
- dispose = value[Symbol.dispose];
435
- }
436
- if (typeof dispose !== "function")
437
- throw new TypeError("Object not disposable.");
438
- env.stack.push({ value: value, dispose: dispose, async: async });
439
- }
440
- else if (async) {
441
- env.stack.push({ async: true });
442
- }
443
- return value;
444
- }
445
- var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
446
- var e = new Error(message);
447
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
448
- };
449
- function __disposeResources(env) {
450
- function fail(e) {
451
- env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
452
- env.hasError = true;
453
- }
454
- function next() {
455
- while (env.stack.length) {
456
- var rec = env.stack.pop();
457
- try {
458
- var result = rec.dispose && rec.dispose.call(rec.value);
459
- if (rec.async)
460
- return Promise.resolve(result).then(next, function (e) { fail(e); return next(); });
461
- }
462
- catch (e) {
463
- fail(e);
464
- }
465
- }
466
- if (env.hasError)
467
- throw env.error;
468
- }
469
- return next();
470
- }
471
- var tslib_es6 = {
472
- __extends: __extends,
473
- __assign: __assign,
474
- __rest: __rest,
475
- __decorate: __decorate,
476
- __param: __param,
477
- __metadata: __metadata,
478
- __awaiter: __awaiter,
479
- __generator: __generator,
480
- __createBinding: __createBinding,
481
- __exportStar: __exportStar,
482
- __values: __values,
483
- __read: __read,
484
- __spread: __spread,
485
- __spreadArrays: __spreadArrays,
486
- __spreadArray: __spreadArray,
487
- __await: __await,
488
- __asyncGenerator: __asyncGenerator,
489
- __asyncDelegator: __asyncDelegator,
490
- __asyncValues: __asyncValues,
491
- __makeTemplateObject: __makeTemplateObject,
492
- __importStar: __importStar,
493
- __importDefault: __importDefault,
494
- __classPrivateFieldGet: __classPrivateFieldGet,
495
- __classPrivateFieldSet: __classPrivateFieldSet,
496
- __classPrivateFieldIn: __classPrivateFieldIn,
497
- __addDisposableResource: __addDisposableResource,
498
- __disposeResources: __disposeResources,
499
- };
500
-
501
- var HmrStateContextFactory = /** @class */ (function () {
502
- function HmrStateContextFactory(module) {
503
- var store$1 = module.injector.get(store.Store, undefined);
504
- if (!store$1) {
505
- throw new Error('Store not found, maybe you forgot to import the NgxsModule');
506
- }
507
- this.store = store$1;
508
- }
509
- /**
510
- * @description
511
- * must be taken out into @ngxs/store/internals
512
- */
513
- HmrStateContextFactory.prototype.createStateContext = function () {
514
- var _this = this;
515
- return {
516
- dispatch: function (actions) { return _this.store.dispatch(actions); },
517
- getState: function () { return _this.store.snapshot(); },
518
- setState: function (val) {
519
- if (operators.isStateOperator(val)) {
520
- var currentState = _this.store.snapshot();
521
- val = val(currentState);
522
- }
523
- _this.store.reset(val);
524
- return val;
525
- },
526
- patchState: function (val) {
527
- var currentState = _this.store.snapshot();
528
- var newState = Object.assign(Object.assign({}, currentState), val);
529
- _this.store.reset(newState);
530
- return newState;
531
- }
532
- };
533
- };
534
- return HmrStateContextFactory;
535
- }());
536
-
537
- var HmrOptionBuilder = /** @class */ (function () {
538
- function HmrOptionBuilder(_a) {
539
- var deferTime = _a.deferTime, autoClearLogs = _a.autoClearLogs;
540
- this.deferTime = deferTime || 100;
541
- this.autoClearLogs = autoClearLogs === undefined ? true : autoClearLogs;
542
- }
543
- HmrOptionBuilder.prototype.clearLogs = function () {
544
- if (this.autoClearLogs) {
545
- console.clear();
546
- }
547
- };
548
- return HmrOptionBuilder;
549
- }());
550
-
551
- var HmrLifecycle = /** @class */ (function () {
552
- function HmrLifecycle(ngAppModule, bootstrap, storage, context, options) {
553
- this.ngAppModule = ngAppModule;
554
- this.bootstrap = bootstrap;
555
- this.storage = storage;
556
- this.context = context;
557
- this.options = options;
558
- }
559
- HmrLifecycle.prototype.hmrNgxsStoreOnInit = function (hmrAfterOnInit) {
560
- var moduleHmrInit = this.getModuleHmrInitCallback();
561
- moduleHmrInit = moduleHmrInit.bind(this.ngAppModule);
562
- this.detectIvyWithJIT();
563
- this.stateEventLoop(function (ctx, state) {
564
- moduleHmrInit(ctx, state);
565
- hmrAfterOnInit(ctx, state);
566
- });
567
- };
568
- HmrLifecycle.prototype.getModuleHmrInitCallback = function () {
569
- if (typeof this.ngAppModule.hmrNgxsStoreOnInit === 'function') {
570
- return this.ngAppModule.hmrNgxsStoreOnInit;
571
- }
572
- return function defaultModuleHmrInit(ctx, state) {
573
- ctx.patchState(state);
574
- };
575
- };
576
- HmrLifecycle.prototype.hmrNgxsStoreBeforeOnDestroy = function () {
577
- var state = {};
578
- var ctx = this.context.createStateContext();
579
- if (typeof this.ngAppModule.hmrNgxsStoreBeforeOnDestroy === 'function') {
580
- state = this.ngAppModule.hmrNgxsStoreBeforeOnDestroy(ctx);
581
- }
582
- else {
583
- state = ctx.getState();
584
- }
585
- ctx.dispatch(new HmrBeforeDestroyAction(state));
586
- return state;
587
- };
588
- HmrLifecycle.prototype.stateEventLoop = function (callback) {
589
- var _this = this;
590
- if (!this.storage.hasData())
591
- return;
592
- var appBootstrapped$ = this.bootstrap.appBootstrapped$;
593
- var state$ = this.context.store.select(function (state) { return state; });
594
- appBootstrapped$.subscribe(function () {
595
- var eventId;
596
- var storeEventId = state$.subscribe(function () {
597
- // setTimeout used for zone detection after set hmr state
598
- clearInterval(eventId);
599
- eventId = window.setTimeout(function () {
600
- // close check on the message queue
601
- storeEventId.unsubscribe();
602
- // if events are no longer running on the call stack,
603
- // then we can update the state
604
- callback(_this.context.createStateContext(), _this.storage.snapshot);
605
- }, _this.options.deferTime);
606
- });
607
- });
608
- };
609
- HmrLifecycle.prototype.detectIvyWithJIT = function () {
610
- var jit = this.ngAppModule.constructor.hasOwnProperty('__annotations__');
611
- var ivy = this.ngAppModule.constructor.hasOwnProperty('ɵmod');
612
- if (jit && ivy) {
613
- throw new Error("@ngxs/hmr-plugin doesn't work with JIT mode in Angular Ivy. Please use AOT mode.");
614
- }
615
- };
616
- return HmrLifecycle;
617
- }());
618
-
619
- var HmrManager = /** @class */ (function () {
620
- function HmrManager(options, storage) {
621
- this.storage = storage;
622
- this.optionsBuilder = new HmrOptionBuilder(options);
623
- }
624
- Object.defineProperty(HmrManager.prototype, "applicationRef", {
625
- get: function () {
626
- return this.ngModule.injector.get(core.ApplicationRef);
627
- },
628
- enumerable: false,
629
- configurable: true
630
- });
631
- Object.defineProperty(HmrManager.prototype, "bootstrap", {
632
- get: function () {
633
- return this.ngModule.injector.get(internals.NgxsBootstrapper);
634
- },
635
- enumerable: false,
636
- configurable: true
637
- });
638
- HmrManager.prototype.hmrModule = function (bootstrapFn, tick) {
639
- return __awaiter(this, void 0, void 0, function () {
640
- var _b;
641
- return __generator(this, function (_c) {
642
- switch (_c.label) {
643
- case 0:
644
- internals.InitialState.set(this.storage.snapshot);
645
- _b = this;
646
- return [4 /*yield*/, bootstrapFn()];
647
- case 1:
648
- _b.ngModule = _c.sent();
649
- this.context = new HmrStateContextFactory(this.ngModule);
650
- this.lifecycle = this.createLifecycle();
651
- tick();
652
- internals.InitialState.pop();
653
- return [2 /*return*/, this.ngModule];
654
- }
655
- });
656
- });
657
- };
658
- HmrManager.prototype.beforeModuleBootstrap = function () {
659
- this.lifecycle.hmrNgxsStoreOnInit(function (ctx, state) {
660
- ctx.dispatch(new HmrInitAction(state));
661
- });
662
- };
663
- HmrManager.prototype.beforeModuleOnDestroy = function () {
664
- this.optionsBuilder.clearLogs();
665
- return this.lifecycle.hmrNgxsStoreBeforeOnDestroy();
666
- };
667
- HmrManager.prototype.createNewModule = function () {
668
- var removeOldHosts = this.cloneHostsBeforeDestroy();
669
- this.removeNgStyles();
670
- this.ngModule.destroy();
671
- removeOldHosts();
672
- };
673
- HmrManager.prototype.createLifecycle = function () {
674
- return new HmrLifecycle(this.ngModule.instance, this.bootstrap, this.storage, this.context, this.optionsBuilder);
675
- };
676
- HmrManager.prototype.cloneHostsBeforeDestroy = function () {
677
- var elements = this.applicationRef.components.map(function (component) { return component.location.nativeElement; });
678
- var removableList = elements.map(function (componentNode) {
679
- var newNode = document.createElement(componentNode.tagName);
680
- var parentNode = componentNode.parentNode;
681
- var currentDisplay = newNode.style.display;
682
- newNode.style.display = 'none';
683
- parentNode.insertBefore(newNode, componentNode);
684
- return function () {
685
- newNode.style.display = currentDisplay;
686
- try {
687
- parentNode.removeChild(componentNode);
688
- }
689
- catch (_a) { }
690
- };
691
- });
692
- return function removeOldHosts() {
693
- removableList.forEach(function (removeOldHost) { return removeOldHost(); });
694
- };
695
- };
696
- HmrManager.prototype.removeNgStyles = function () {
697
- var head = document.head;
698
- var styles = Array.from(head.querySelectorAll('style'));
699
- styles
700
- .filter(function (style) { return style.innerText.includes('_ng'); })
701
- .map(function (style) { return head.removeChild(style); });
702
- };
703
- return HmrManager;
704
- }());
705
-
706
- var HmrStorage = /** @class */ (function () {
707
- function HmrStorage(_snapshot) {
708
- if (_snapshot === void 0) { _snapshot = {}; }
709
- this._snapshot = _snapshot;
710
- }
711
- HmrStorage.prototype.hasData = function () {
712
- return Object.keys(this._snapshot).length > 0;
713
- };
714
- Object.defineProperty(HmrStorage.prototype, "snapshot", {
715
- get: function () {
716
- return this._snapshot;
717
- },
718
- enumerable: false,
719
- configurable: true
720
- });
721
- return HmrStorage;
722
- }());
723
-
724
- function setHmrReloadedTo(value) {
725
- if (window["NGXS_HMR_LIFECYCLE_STATUS" /* Status */]) {
726
- window["NGXS_HMR_LIFECYCLE_STATUS" /* Status */].hmrReloaded = value;
727
- }
728
- }
729
- function markApplicationAsHmrReloaded() {
730
- window["NGXS_HMR_LIFECYCLE_STATUS" /* Status */] = window["NGXS_HMR_LIFECYCLE_STATUS" /* Status */] || {
731
- hmrReloaded: false
732
- };
733
- }
734
-
735
- /**
736
- * Hot Module Replacement plugin for NGXS
737
- * @deprecated As of Angular v10, HMR is no longer supported and will be deprecated.
738
- * More information [here](https://www.ngxs.io/plugins/hmr).
739
- */
740
- function hmr(webpackModule, bootstrapFn, options) {
741
- if (options === void 0) { options = {}; }
742
- return __awaiter(this, void 0, void 0, function () {
743
- var dataTransfer, storage, manager;
744
- return __generator(this, function (_a) {
745
- switch (_a.label) {
746
- case 0:
747
- if (!webpackModule.hot) {
748
- console.error('Are you using the --hmr flag for ng serve?');
749
- throw new Error('HMR is not enabled for webpack-dev-server!');
750
- }
751
- markApplicationAsHmrReloaded();
752
- webpackModule.hot.accept();
753
- dataTransfer = webpackModule.hot.data || {};
754
- storage = new HmrStorage(dataTransfer.snapshot || {});
755
- manager = new HmrManager(options, storage);
756
- return [4 /*yield*/, manager.hmrModule(bootstrapFn, function () {
757
- manager.beforeModuleBootstrap();
758
- webpackModule.hot.dispose(function (data) {
759
- setHmrReloadedTo(true);
760
- data.snapshot = manager.beforeModuleOnDestroy();
761
- manager.createNewModule();
762
- });
763
- })];
764
- case 1: return [2 /*return*/, _a.sent()];
765
- }
766
- });
767
- });
768
- }
769
-
770
- function hmrIsReloaded() {
771
- return !!(window["NGXS_HMR_LIFECYCLE_STATUS" /* Status */] && window["NGXS_HMR_LIFECYCLE_STATUS" /* Status */].hmrReloaded);
772
- }
773
-
774
- /**
775
- * The public api for consumers of @ngxs/hmr-plugin
776
- */
777
-
778
- /**
779
- * Generated bundle index. Do not edit.
780
- */
781
-
782
- exports.HmrBeforeDestroyAction = HmrBeforeDestroyAction;
783
- exports.HmrInitAction = HmrInitAction;
784
- exports.hmr = hmr;
785
- exports.hmrIsReloaded = hmrIsReloaded;
786
-
787
- Object.defineProperty(exports, '__esModule', { value: true });
788
-
789
- }));
790
- //# sourceMappingURL=ngxs-hmr-plugin.umd.js.map