@ngrx/store-devtools 13.0.0-beta.0 → 13.0.0-rc.0

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 (44) hide show
  1. package/{esm2015/index.js → esm2020/index.mjs} +0 -0
  2. package/{esm2015/ngrx-store-devtools.js → esm2020/ngrx-store-devtools.mjs} +0 -0
  3. package/{esm2015/public_api.js → esm2020/public_api.mjs} +0 -0
  4. package/{esm2015/src/actions.js → esm2020/src/actions.mjs} +0 -0
  5. package/{esm2015/src/config.js → esm2020/src/config.mjs} +0 -0
  6. package/{esm2015/src/devtools-dispatcher.js → esm2020/src/devtools-dispatcher.mjs} +4 -4
  7. package/{esm2015/src/devtools.js → esm2020/src/devtools.mjs} +4 -4
  8. package/esm2020/src/extension.mjs +161 -0
  9. package/{esm2015/src/index.js → esm2020/src/index.mjs} +0 -0
  10. package/{esm2015/src/instrument.js → esm2020/src/instrument.mjs} +5 -5
  11. package/esm2020/src/reducer.mjs +368 -0
  12. package/esm2020/src/utils.mjs +114 -0
  13. package/fesm2015/ngrx-store-devtools.mjs +959 -0
  14. package/fesm2015/ngrx-store-devtools.mjs.map +1 -0
  15. package/{fesm2015/ngrx-store-devtools.js → fesm2020/ngrx-store-devtools.mjs} +37 -22
  16. package/fesm2020/ngrx-store-devtools.mjs.map +1 -0
  17. package/migrations/6_0_0/index.js +1 -1
  18. package/migrations/6_0_0/index.js.map +1 -1
  19. package/package.json +22 -9
  20. package/schematics/ng-add/index.js +12 -12
  21. package/schematics/ng-add/index.js.map +1 -1
  22. package/schematics-core/utility/angular-utils.js +6 -5
  23. package/schematics-core/utility/angular-utils.js.map +1 -1
  24. package/schematics-core/utility/ast-utils.js +12 -8
  25. package/schematics-core/utility/ast-utils.js.map +1 -1
  26. package/schematics-core/utility/find-component.js +12 -12
  27. package/schematics-core/utility/find-component.js.map +1 -1
  28. package/schematics-core/utility/find-module.js +12 -12
  29. package/schematics-core/utility/find-module.js.map +1 -1
  30. package/schematics-core/utility/json-utilts.js.map +1 -1
  31. package/schematics-core/utility/ngrx-utils.js +16 -12
  32. package/schematics-core/utility/ngrx-utils.js.map +1 -1
  33. package/schematics-core/utility/parse-name.js +3 -3
  34. package/schematics-core/utility/parse-name.js.map +1 -1
  35. package/schematics-core/utility/project.js +1 -1
  36. package/schematics-core/utility/project.js.map +1 -1
  37. package/schematics-core/utility/visitors.js +2 -2
  38. package/schematics-core/utility/visitors.js.map +1 -1
  39. package/bundles/ngrx-store-devtools.umd.js +0 -1330
  40. package/bundles/ngrx-store-devtools.umd.js.map +0 -1
  41. package/esm2015/src/extension.js +0 -157
  42. package/esm2015/src/reducer.js +0 -365
  43. package/esm2015/src/utils.js +0 -106
  44. package/fesm2015/ngrx-store-devtools.js.map +0 -1
@@ -0,0 +1,959 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, Injectable, Inject, NgModule } from '@angular/core';
3
+ import * as i2 from '@ngrx/store';
4
+ import { INIT, UPDATE, ActionsSubject, INITIAL_STATE, StateObservable, ReducerManagerDispatcher } from '@ngrx/store';
5
+ import { EMPTY, Observable, of, merge, queueScheduler, ReplaySubject } from 'rxjs';
6
+ import { share, filter, map, concatMap, timeout, debounceTime, catchError, take, takeUntil, switchMap, skip, observeOn, withLatestFrom, scan } from 'rxjs/operators';
7
+
8
+ /**
9
+ * Chrome extension documentation
10
+ * @see https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md
11
+ * Firefox extension documentation
12
+ * @see https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md
13
+ */
14
+ class StoreDevtoolsConfig {
15
+ constructor() {
16
+ /**
17
+ * Maximum allowed actions to be stored in the history tree (default: `false`)
18
+ */
19
+ this.maxAge = false;
20
+ }
21
+ }
22
+ const STORE_DEVTOOLS_CONFIG = new InjectionToken('@ngrx/store-devtools Options');
23
+ /**
24
+ * Used to provide a `StoreDevtoolsConfig` for the store-devtools.
25
+ */
26
+ const INITIAL_OPTIONS = new InjectionToken('@ngrx/store-devtools Initial Config');
27
+ function noMonitor() {
28
+ return null;
29
+ }
30
+ const DEFAULT_NAME = 'NgRx Store DevTools';
31
+ function createConfig(optionsInput) {
32
+ const DEFAULT_OPTIONS = {
33
+ maxAge: false,
34
+ monitor: noMonitor,
35
+ actionSanitizer: undefined,
36
+ stateSanitizer: undefined,
37
+ name: DEFAULT_NAME,
38
+ serialize: false,
39
+ logOnly: false,
40
+ autoPause: false,
41
+ // Add all features explicitly. This prevent buggy behavior for
42
+ // options like "lock" which might otherwise not show up.
43
+ features: {
44
+ pause: true,
45
+ lock: true,
46
+ persist: true,
47
+ export: true,
48
+ import: 'custom',
49
+ jump: true,
50
+ skip: true,
51
+ reorder: true,
52
+ dispatch: true,
53
+ test: true, // Generate tests for the selected actions
54
+ },
55
+ };
56
+ const options = typeof optionsInput === 'function' ? optionsInput() : optionsInput;
57
+ const logOnly = options.logOnly
58
+ ? { pause: true, export: true, test: true }
59
+ : false;
60
+ const features = options.features || logOnly || DEFAULT_OPTIONS.features;
61
+ const config = Object.assign({}, DEFAULT_OPTIONS, { features }, options);
62
+ if (config.maxAge && config.maxAge < 2) {
63
+ throw new Error(`Devtools 'maxAge' cannot be less than 2, got ${config.maxAge}`);
64
+ }
65
+ return config;
66
+ }
67
+
68
+ const PERFORM_ACTION = 'PERFORM_ACTION';
69
+ const REFRESH = 'REFRESH';
70
+ const RESET = 'RESET';
71
+ const ROLLBACK = 'ROLLBACK';
72
+ const COMMIT = 'COMMIT';
73
+ const SWEEP = 'SWEEP';
74
+ const TOGGLE_ACTION = 'TOGGLE_ACTION';
75
+ const SET_ACTIONS_ACTIVE = 'SET_ACTIONS_ACTIVE';
76
+ const JUMP_TO_STATE = 'JUMP_TO_STATE';
77
+ const JUMP_TO_ACTION = 'JUMP_TO_ACTION';
78
+ const IMPORT_STATE = 'IMPORT_STATE';
79
+ const LOCK_CHANGES = 'LOCK_CHANGES';
80
+ const PAUSE_RECORDING = 'PAUSE_RECORDING';
81
+ class PerformAction {
82
+ constructor(action, timestamp) {
83
+ this.action = action;
84
+ this.timestamp = timestamp;
85
+ this.type = PERFORM_ACTION;
86
+ if (typeof action.type === 'undefined') {
87
+ throw new Error('Actions may not have an undefined "type" property. ' +
88
+ 'Have you misspelled a constant?');
89
+ }
90
+ }
91
+ }
92
+ class Refresh {
93
+ constructor() {
94
+ this.type = REFRESH;
95
+ }
96
+ }
97
+ class Reset {
98
+ constructor(timestamp) {
99
+ this.timestamp = timestamp;
100
+ this.type = RESET;
101
+ }
102
+ }
103
+ class Rollback {
104
+ constructor(timestamp) {
105
+ this.timestamp = timestamp;
106
+ this.type = ROLLBACK;
107
+ }
108
+ }
109
+ class Commit {
110
+ constructor(timestamp) {
111
+ this.timestamp = timestamp;
112
+ this.type = COMMIT;
113
+ }
114
+ }
115
+ class Sweep {
116
+ constructor() {
117
+ this.type = SWEEP;
118
+ }
119
+ }
120
+ class ToggleAction {
121
+ constructor(id) {
122
+ this.id = id;
123
+ this.type = TOGGLE_ACTION;
124
+ }
125
+ }
126
+ class SetActionsActive {
127
+ constructor(start, end, active = true) {
128
+ this.start = start;
129
+ this.end = end;
130
+ this.active = active;
131
+ this.type = SET_ACTIONS_ACTIVE;
132
+ }
133
+ }
134
+ class JumpToState {
135
+ constructor(index) {
136
+ this.index = index;
137
+ this.type = JUMP_TO_STATE;
138
+ }
139
+ }
140
+ class JumpToAction {
141
+ constructor(actionId) {
142
+ this.actionId = actionId;
143
+ this.type = JUMP_TO_ACTION;
144
+ }
145
+ }
146
+ class ImportState {
147
+ constructor(nextLiftedState) {
148
+ this.nextLiftedState = nextLiftedState;
149
+ this.type = IMPORT_STATE;
150
+ }
151
+ }
152
+ class LockChanges {
153
+ constructor(status) {
154
+ this.status = status;
155
+ this.type = LOCK_CHANGES;
156
+ }
157
+ }
158
+ class PauseRecording {
159
+ constructor(status) {
160
+ this.status = status;
161
+ this.type = PAUSE_RECORDING;
162
+ }
163
+ }
164
+
165
+ function difference(first, second) {
166
+ return first.filter((item) => second.indexOf(item) < 0);
167
+ }
168
+ /**
169
+ * Provides an app's view into the state of the lifted store.
170
+ */
171
+ function unliftState(liftedState) {
172
+ const { computedStates, currentStateIndex } = liftedState;
173
+ // At start up NgRx dispatches init actions,
174
+ // When these init actions are being filtered out by the predicate or safe/block list options
175
+ // we don't have a complete computed states yet.
176
+ // At this point it could happen that we're out of bounds, when this happens we fall back to the last known state
177
+ if (currentStateIndex >= computedStates.length) {
178
+ const { state } = computedStates[computedStates.length - 1];
179
+ return state;
180
+ }
181
+ const { state } = computedStates[currentStateIndex];
182
+ return state;
183
+ }
184
+ function unliftAction(liftedState) {
185
+ return liftedState.actionsById[liftedState.nextActionId - 1];
186
+ }
187
+ /**
188
+ * Lifts an app's action into an action on the lifted store.
189
+ */
190
+ function liftAction(action) {
191
+ return new PerformAction(action, +Date.now());
192
+ }
193
+ /**
194
+ * Sanitizes given actions with given function.
195
+ */
196
+ function sanitizeActions(actionSanitizer, actions) {
197
+ return Object.keys(actions).reduce((sanitizedActions, actionIdx) => {
198
+ const idx = Number(actionIdx);
199
+ sanitizedActions[idx] = sanitizeAction(actionSanitizer, actions[idx], idx);
200
+ return sanitizedActions;
201
+ }, {});
202
+ }
203
+ /**
204
+ * Sanitizes given action with given function.
205
+ */
206
+ function sanitizeAction(actionSanitizer, action, actionIdx) {
207
+ return Object.assign(Object.assign({}, action), { action: actionSanitizer(action.action, actionIdx) });
208
+ }
209
+ /**
210
+ * Sanitizes given states with given function.
211
+ */
212
+ function sanitizeStates(stateSanitizer, states) {
213
+ return states.map((computedState, idx) => ({
214
+ state: sanitizeState(stateSanitizer, computedState.state, idx),
215
+ error: computedState.error,
216
+ }));
217
+ }
218
+ /**
219
+ * Sanitizes given state with given function.
220
+ */
221
+ function sanitizeState(stateSanitizer, state, stateIdx) {
222
+ return stateSanitizer(state, stateIdx);
223
+ }
224
+ /**
225
+ * Read the config and tell if actions should be filtered
226
+ */
227
+ function shouldFilterActions(config) {
228
+ return config.predicate || config.actionsSafelist || config.actionsBlocklist;
229
+ }
230
+ /**
231
+ * Return a full filtered lifted state
232
+ */
233
+ function filterLiftedState(liftedState, predicate, safelist, blocklist) {
234
+ const filteredStagedActionIds = [];
235
+ const filteredActionsById = {};
236
+ const filteredComputedStates = [];
237
+ liftedState.stagedActionIds.forEach((id, idx) => {
238
+ const liftedAction = liftedState.actionsById[id];
239
+ if (!liftedAction)
240
+ return;
241
+ if (idx &&
242
+ isActionFiltered(liftedState.computedStates[idx], liftedAction, predicate, safelist, blocklist)) {
243
+ return;
244
+ }
245
+ filteredActionsById[id] = liftedAction;
246
+ filteredStagedActionIds.push(id);
247
+ filteredComputedStates.push(liftedState.computedStates[idx]);
248
+ });
249
+ return Object.assign(Object.assign({}, liftedState), { stagedActionIds: filteredStagedActionIds, actionsById: filteredActionsById, computedStates: filteredComputedStates });
250
+ }
251
+ /**
252
+ * Return true is the action should be ignored
253
+ */
254
+ function isActionFiltered(state, action, predicate, safelist, blockedlist) {
255
+ const predicateMatch = predicate && !predicate(state, action.action);
256
+ const safelistMatch = safelist &&
257
+ !action.action.type.match(safelist.map((s) => escapeRegExp(s)).join('|'));
258
+ const blocklistMatch = blockedlist &&
259
+ action.action.type.match(blockedlist.map((s) => escapeRegExp(s)).join('|'));
260
+ return predicateMatch || safelistMatch || blocklistMatch;
261
+ }
262
+ /**
263
+ * Return string with escaped RegExp special characters
264
+ * https://stackoverflow.com/a/6969486/1337347
265
+ */
266
+ function escapeRegExp(s) {
267
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
268
+ }
269
+
270
+ const INIT_ACTION = { type: INIT };
271
+ const RECOMPUTE = '@ngrx/store-devtools/recompute';
272
+ const RECOMPUTE_ACTION = { type: RECOMPUTE };
273
+ /**
274
+ * Computes the next entry in the log by applying an action.
275
+ */
276
+ function computeNextEntry(reducer, action, state, error, errorHandler) {
277
+ if (error) {
278
+ return {
279
+ state,
280
+ error: 'Interrupted by an error up the chain',
281
+ };
282
+ }
283
+ let nextState = state;
284
+ let nextError;
285
+ try {
286
+ nextState = reducer(state, action);
287
+ }
288
+ catch (err) {
289
+ nextError = err.toString();
290
+ errorHandler.handleError(err);
291
+ }
292
+ return {
293
+ state: nextState,
294
+ error: nextError,
295
+ };
296
+ }
297
+ /**
298
+ * Runs the reducer on invalidated actions to get a fresh computation log.
299
+ */
300
+ function recomputeStates(computedStates, minInvalidatedStateIndex, reducer, committedState, actionsById, stagedActionIds, skippedActionIds, errorHandler, isPaused) {
301
+ // Optimization: exit early and return the same reference
302
+ // if we know nothing could have changed.
303
+ if (minInvalidatedStateIndex >= computedStates.length &&
304
+ computedStates.length === stagedActionIds.length) {
305
+ return computedStates;
306
+ }
307
+ const nextComputedStates = computedStates.slice(0, minInvalidatedStateIndex);
308
+ // If the recording is paused, recompute all states up until the pause state,
309
+ // else recompute all states.
310
+ const lastIncludedActionId = stagedActionIds.length - (isPaused ? 1 : 0);
311
+ for (let i = minInvalidatedStateIndex; i < lastIncludedActionId; i++) {
312
+ const actionId = stagedActionIds[i];
313
+ const action = actionsById[actionId].action;
314
+ const previousEntry = nextComputedStates[i - 1];
315
+ const previousState = previousEntry ? previousEntry.state : committedState;
316
+ const previousError = previousEntry ? previousEntry.error : undefined;
317
+ const shouldSkip = skippedActionIds.indexOf(actionId) > -1;
318
+ const entry = shouldSkip
319
+ ? previousEntry
320
+ : computeNextEntry(reducer, action, previousState, previousError, errorHandler);
321
+ nextComputedStates.push(entry);
322
+ }
323
+ // If the recording is paused, the last state will not be recomputed,
324
+ // because it's essentially not part of the state history.
325
+ if (isPaused) {
326
+ nextComputedStates.push(computedStates[computedStates.length - 1]);
327
+ }
328
+ return nextComputedStates;
329
+ }
330
+ function liftInitialState(initialCommittedState, monitorReducer) {
331
+ return {
332
+ monitorState: monitorReducer(undefined, {}),
333
+ nextActionId: 1,
334
+ actionsById: { 0: liftAction(INIT_ACTION) },
335
+ stagedActionIds: [0],
336
+ skippedActionIds: [],
337
+ committedState: initialCommittedState,
338
+ currentStateIndex: 0,
339
+ computedStates: [],
340
+ isLocked: false,
341
+ isPaused: false,
342
+ };
343
+ }
344
+ /**
345
+ * Creates a history state reducer from an app's reducer.
346
+ */
347
+ function liftReducerWith(initialCommittedState, initialLiftedState, errorHandler, monitorReducer, options = {}) {
348
+ /**
349
+ * Manages how the history actions modify the history state.
350
+ */
351
+ return (reducer) => (liftedState, liftedAction) => {
352
+ let { monitorState, actionsById, nextActionId, stagedActionIds, skippedActionIds, committedState, currentStateIndex, computedStates, isLocked, isPaused, } = liftedState || initialLiftedState;
353
+ if (!liftedState) {
354
+ // Prevent mutating initialLiftedState
355
+ actionsById = Object.create(actionsById);
356
+ }
357
+ function commitExcessActions(n) {
358
+ // Auto-commits n-number of excess actions.
359
+ let excess = n;
360
+ let idsToDelete = stagedActionIds.slice(1, excess + 1);
361
+ for (let i = 0; i < idsToDelete.length; i++) {
362
+ if (computedStates[i + 1].error) {
363
+ // Stop if error is found. Commit actions up to error.
364
+ excess = i;
365
+ idsToDelete = stagedActionIds.slice(1, excess + 1);
366
+ break;
367
+ }
368
+ else {
369
+ delete actionsById[idsToDelete[i]];
370
+ }
371
+ }
372
+ skippedActionIds = skippedActionIds.filter((id) => idsToDelete.indexOf(id) === -1);
373
+ stagedActionIds = [0, ...stagedActionIds.slice(excess + 1)];
374
+ committedState = computedStates[excess].state;
375
+ computedStates = computedStates.slice(excess);
376
+ currentStateIndex =
377
+ currentStateIndex > excess ? currentStateIndex - excess : 0;
378
+ }
379
+ function commitChanges() {
380
+ // Consider the last committed state the new starting point.
381
+ // Squash any staged actions into a single committed state.
382
+ actionsById = { 0: liftAction(INIT_ACTION) };
383
+ nextActionId = 1;
384
+ stagedActionIds = [0];
385
+ skippedActionIds = [];
386
+ committedState = computedStates[currentStateIndex].state;
387
+ currentStateIndex = 0;
388
+ computedStates = [];
389
+ }
390
+ // By default, aggressively recompute every state whatever happens.
391
+ // This has O(n) performance, so we'll override this to a sensible
392
+ // value whenever we feel like we don't have to recompute the states.
393
+ let minInvalidatedStateIndex = 0;
394
+ switch (liftedAction.type) {
395
+ case LOCK_CHANGES: {
396
+ isLocked = liftedAction.status;
397
+ minInvalidatedStateIndex = Infinity;
398
+ break;
399
+ }
400
+ case PAUSE_RECORDING: {
401
+ isPaused = liftedAction.status;
402
+ if (isPaused) {
403
+ // Add a pause action to signal the devtools-user the recording is paused.
404
+ // The corresponding state will be overwritten on each update to always contain
405
+ // the latest state (see Actions.PERFORM_ACTION).
406
+ stagedActionIds = [...stagedActionIds, nextActionId];
407
+ actionsById[nextActionId] = new PerformAction({
408
+ type: '@ngrx/devtools/pause',
409
+ }, +Date.now());
410
+ nextActionId++;
411
+ minInvalidatedStateIndex = stagedActionIds.length - 1;
412
+ computedStates = computedStates.concat(computedStates[computedStates.length - 1]);
413
+ if (currentStateIndex === stagedActionIds.length - 2) {
414
+ currentStateIndex++;
415
+ }
416
+ minInvalidatedStateIndex = Infinity;
417
+ }
418
+ else {
419
+ commitChanges();
420
+ }
421
+ break;
422
+ }
423
+ case RESET: {
424
+ // Get back to the state the store was created with.
425
+ actionsById = { 0: liftAction(INIT_ACTION) };
426
+ nextActionId = 1;
427
+ stagedActionIds = [0];
428
+ skippedActionIds = [];
429
+ committedState = initialCommittedState;
430
+ currentStateIndex = 0;
431
+ computedStates = [];
432
+ break;
433
+ }
434
+ case COMMIT: {
435
+ commitChanges();
436
+ break;
437
+ }
438
+ case ROLLBACK: {
439
+ // Forget about any staged actions.
440
+ // Start again from the last committed state.
441
+ actionsById = { 0: liftAction(INIT_ACTION) };
442
+ nextActionId = 1;
443
+ stagedActionIds = [0];
444
+ skippedActionIds = [];
445
+ currentStateIndex = 0;
446
+ computedStates = [];
447
+ break;
448
+ }
449
+ case TOGGLE_ACTION: {
450
+ // Toggle whether an action with given ID is skipped.
451
+ // Being skipped means it is a no-op during the computation.
452
+ const { id: actionId } = liftedAction;
453
+ const index = skippedActionIds.indexOf(actionId);
454
+ if (index === -1) {
455
+ skippedActionIds = [actionId, ...skippedActionIds];
456
+ }
457
+ else {
458
+ skippedActionIds = skippedActionIds.filter((id) => id !== actionId);
459
+ }
460
+ // Optimization: we know history before this action hasn't changed
461
+ minInvalidatedStateIndex = stagedActionIds.indexOf(actionId);
462
+ break;
463
+ }
464
+ case SET_ACTIONS_ACTIVE: {
465
+ // Toggle whether an action with given ID is skipped.
466
+ // Being skipped means it is a no-op during the computation.
467
+ const { start, end, active } = liftedAction;
468
+ const actionIds = [];
469
+ for (let i = start; i < end; i++)
470
+ actionIds.push(i);
471
+ if (active) {
472
+ skippedActionIds = difference(skippedActionIds, actionIds);
473
+ }
474
+ else {
475
+ skippedActionIds = [...skippedActionIds, ...actionIds];
476
+ }
477
+ // Optimization: we know history before this action hasn't changed
478
+ minInvalidatedStateIndex = stagedActionIds.indexOf(start);
479
+ break;
480
+ }
481
+ case JUMP_TO_STATE: {
482
+ // Without recomputing anything, move the pointer that tell us
483
+ // which state is considered the current one. Useful for sliders.
484
+ currentStateIndex = liftedAction.index;
485
+ // Optimization: we know the history has not changed.
486
+ minInvalidatedStateIndex = Infinity;
487
+ break;
488
+ }
489
+ case JUMP_TO_ACTION: {
490
+ // Jumps to a corresponding state to a specific action.
491
+ // Useful when filtering actions.
492
+ const index = stagedActionIds.indexOf(liftedAction.actionId);
493
+ if (index !== -1)
494
+ currentStateIndex = index;
495
+ minInvalidatedStateIndex = Infinity;
496
+ break;
497
+ }
498
+ case SWEEP: {
499
+ // Forget any actions that are currently being skipped.
500
+ stagedActionIds = difference(stagedActionIds, skippedActionIds);
501
+ skippedActionIds = [];
502
+ currentStateIndex = Math.min(currentStateIndex, stagedActionIds.length - 1);
503
+ break;
504
+ }
505
+ case PERFORM_ACTION: {
506
+ // Ignore action and return state as is if recording is locked
507
+ if (isLocked) {
508
+ return liftedState || initialLiftedState;
509
+ }
510
+ if (isPaused ||
511
+ (liftedState &&
512
+ isActionFiltered(liftedState.computedStates[currentStateIndex], liftedAction, options.predicate, options.actionsSafelist, options.actionsBlocklist))) {
513
+ // If recording is paused or if the action should be ignored, overwrite the last state
514
+ // (corresponds to the pause action) and keep everything else as is.
515
+ // This way, the app gets the new current state while the devtools
516
+ // do not record another action.
517
+ const lastState = computedStates[computedStates.length - 1];
518
+ computedStates = [
519
+ ...computedStates.slice(0, -1),
520
+ computeNextEntry(reducer, liftedAction.action, lastState.state, lastState.error, errorHandler),
521
+ ];
522
+ minInvalidatedStateIndex = Infinity;
523
+ break;
524
+ }
525
+ // Auto-commit as new actions come in.
526
+ if (options.maxAge && stagedActionIds.length === options.maxAge) {
527
+ commitExcessActions(1);
528
+ }
529
+ if (currentStateIndex === stagedActionIds.length - 1) {
530
+ currentStateIndex++;
531
+ }
532
+ const actionId = nextActionId++;
533
+ // Mutation! This is the hottest path, and we optimize on purpose.
534
+ // It is safe because we set a new key in a cache dictionary.
535
+ actionsById[actionId] = liftedAction;
536
+ stagedActionIds = [...stagedActionIds, actionId];
537
+ // Optimization: we know that only the new action needs computing.
538
+ minInvalidatedStateIndex = stagedActionIds.length - 1;
539
+ break;
540
+ }
541
+ case IMPORT_STATE: {
542
+ // Completely replace everything.
543
+ ({
544
+ monitorState,
545
+ actionsById,
546
+ nextActionId,
547
+ stagedActionIds,
548
+ skippedActionIds,
549
+ committedState,
550
+ currentStateIndex,
551
+ computedStates,
552
+ isLocked,
553
+ isPaused,
554
+ } = liftedAction.nextLiftedState);
555
+ break;
556
+ }
557
+ case INIT: {
558
+ // Always recompute states on hot reload and init.
559
+ minInvalidatedStateIndex = 0;
560
+ if (options.maxAge && stagedActionIds.length > options.maxAge) {
561
+ // States must be recomputed before committing excess.
562
+ computedStates = recomputeStates(computedStates, minInvalidatedStateIndex, reducer, committedState, actionsById, stagedActionIds, skippedActionIds, errorHandler, isPaused);
563
+ commitExcessActions(stagedActionIds.length - options.maxAge);
564
+ // Avoid double computation.
565
+ minInvalidatedStateIndex = Infinity;
566
+ }
567
+ break;
568
+ }
569
+ case UPDATE: {
570
+ const stateHasErrors = computedStates.filter((state) => state.error).length > 0;
571
+ if (stateHasErrors) {
572
+ // Recompute all states
573
+ minInvalidatedStateIndex = 0;
574
+ if (options.maxAge && stagedActionIds.length > options.maxAge) {
575
+ // States must be recomputed before committing excess.
576
+ computedStates = recomputeStates(computedStates, minInvalidatedStateIndex, reducer, committedState, actionsById, stagedActionIds, skippedActionIds, errorHandler, isPaused);
577
+ commitExcessActions(stagedActionIds.length - options.maxAge);
578
+ // Avoid double computation.
579
+ minInvalidatedStateIndex = Infinity;
580
+ }
581
+ }
582
+ else {
583
+ // If not paused/locked, add a new action to signal devtools-user
584
+ // that there was a reducer update.
585
+ if (!isPaused && !isLocked) {
586
+ if (currentStateIndex === stagedActionIds.length - 1) {
587
+ currentStateIndex++;
588
+ }
589
+ // Add a new action to only recompute state
590
+ const actionId = nextActionId++;
591
+ actionsById[actionId] = new PerformAction(liftedAction, +Date.now());
592
+ stagedActionIds = [...stagedActionIds, actionId];
593
+ minInvalidatedStateIndex = stagedActionIds.length - 1;
594
+ computedStates = recomputeStates(computedStates, minInvalidatedStateIndex, reducer, committedState, actionsById, stagedActionIds, skippedActionIds, errorHandler, isPaused);
595
+ }
596
+ // Recompute state history with latest reducer and update action
597
+ computedStates = computedStates.map((cmp) => (Object.assign(Object.assign({}, cmp), { state: reducer(cmp.state, RECOMPUTE_ACTION) })));
598
+ currentStateIndex = stagedActionIds.length - 1;
599
+ if (options.maxAge && stagedActionIds.length > options.maxAge) {
600
+ commitExcessActions(stagedActionIds.length - options.maxAge);
601
+ }
602
+ // Avoid double computation.
603
+ minInvalidatedStateIndex = Infinity;
604
+ }
605
+ break;
606
+ }
607
+ default: {
608
+ // If the action is not recognized, it's a monitor action.
609
+ // Optimization: a monitor action can't change history.
610
+ minInvalidatedStateIndex = Infinity;
611
+ break;
612
+ }
613
+ }
614
+ computedStates = recomputeStates(computedStates, minInvalidatedStateIndex, reducer, committedState, actionsById, stagedActionIds, skippedActionIds, errorHandler, isPaused);
615
+ monitorState = monitorReducer(monitorState, liftedAction);
616
+ return {
617
+ monitorState,
618
+ actionsById,
619
+ nextActionId,
620
+ stagedActionIds,
621
+ skippedActionIds,
622
+ committedState,
623
+ currentStateIndex,
624
+ computedStates,
625
+ isLocked,
626
+ isPaused,
627
+ };
628
+ };
629
+ }
630
+
631
+ class DevtoolsDispatcher extends ActionsSubject {
632
+ }
633
+ /** @nocollapse */ /** @nocollapse */ DevtoolsDispatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: DevtoolsDispatcher, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
634
+ /** @nocollapse */ /** @nocollapse */ DevtoolsDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: DevtoolsDispatcher });
635
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: DevtoolsDispatcher, decorators: [{
636
+ type: Injectable
637
+ }] });
638
+
639
+ const ExtensionActionTypes = {
640
+ START: 'START',
641
+ DISPATCH: 'DISPATCH',
642
+ STOP: 'STOP',
643
+ ACTION: 'ACTION',
644
+ };
645
+ const REDUX_DEVTOOLS_EXTENSION = new InjectionToken('@ngrx/store-devtools Redux Devtools Extension');
646
+ class DevtoolsExtension {
647
+ constructor(devtoolsExtension, config, dispatcher) {
648
+ this.config = config;
649
+ this.dispatcher = dispatcher;
650
+ this.devtoolsExtension = devtoolsExtension;
651
+ this.createActionStreams();
652
+ }
653
+ notify(action, state) {
654
+ if (!this.devtoolsExtension) {
655
+ return;
656
+ }
657
+ // Check to see if the action requires a full update of the liftedState.
658
+ // If it is a simple action generated by the user's app and the recording
659
+ // is not locked/paused, only send the action and the current state (fast).
660
+ //
661
+ // A full liftedState update (slow: serializes the entire liftedState) is
662
+ // only required when:
663
+ // a) redux-devtools-extension fires the @@Init action (ignored by
664
+ // @ngrx/store-devtools)
665
+ // b) an action is generated by an @ngrx module (e.g. @ngrx/effects/init
666
+ // or @ngrx/store/update-reducers)
667
+ // c) the state has been recomputed due to time-traveling
668
+ // d) any action that is not a PerformAction to err on the side of
669
+ // caution.
670
+ if (action.type === PERFORM_ACTION) {
671
+ if (state.isLocked || state.isPaused) {
672
+ return;
673
+ }
674
+ const currentState = unliftState(state);
675
+ if (shouldFilterActions(this.config) &&
676
+ isActionFiltered(currentState, action, this.config.predicate, this.config.actionsSafelist, this.config.actionsBlocklist)) {
677
+ return;
678
+ }
679
+ const sanitizedState = this.config.stateSanitizer
680
+ ? sanitizeState(this.config.stateSanitizer, currentState, state.currentStateIndex)
681
+ : currentState;
682
+ const sanitizedAction = this.config.actionSanitizer
683
+ ? sanitizeAction(this.config.actionSanitizer, action, state.nextActionId)
684
+ : action;
685
+ this.sendToReduxDevtools(() => this.extensionConnection.send(sanitizedAction, sanitizedState));
686
+ }
687
+ else {
688
+ // Requires full state update
689
+ const sanitizedLiftedState = Object.assign(Object.assign({}, state), { stagedActionIds: state.stagedActionIds, actionsById: this.config.actionSanitizer
690
+ ? sanitizeActions(this.config.actionSanitizer, state.actionsById)
691
+ : state.actionsById, computedStates: this.config.stateSanitizer
692
+ ? sanitizeStates(this.config.stateSanitizer, state.computedStates)
693
+ : state.computedStates });
694
+ this.sendToReduxDevtools(() => this.devtoolsExtension.send(null, sanitizedLiftedState, this.getExtensionConfig(this.config)));
695
+ }
696
+ }
697
+ createChangesObservable() {
698
+ if (!this.devtoolsExtension) {
699
+ return EMPTY;
700
+ }
701
+ return new Observable((subscriber) => {
702
+ const connection = this.devtoolsExtension.connect(this.getExtensionConfig(this.config));
703
+ this.extensionConnection = connection;
704
+ connection.init();
705
+ connection.subscribe((change) => subscriber.next(change));
706
+ return connection.unsubscribe;
707
+ });
708
+ }
709
+ createActionStreams() {
710
+ // Listens to all changes
711
+ const changes$ = this.createChangesObservable().pipe(share());
712
+ // Listen for the start action
713
+ const start$ = changes$.pipe(filter((change) => change.type === ExtensionActionTypes.START));
714
+ // Listen for the stop action
715
+ const stop$ = changes$.pipe(filter((change) => change.type === ExtensionActionTypes.STOP));
716
+ // Listen for lifted actions
717
+ const liftedActions$ = changes$.pipe(filter((change) => change.type === ExtensionActionTypes.DISPATCH), map((change) => this.unwrapAction(change.payload)), concatMap((action) => {
718
+ if (action.type === IMPORT_STATE) {
719
+ // State imports may happen in two situations:
720
+ // 1. Explicitly by user
721
+ // 2. User activated the "persist state accross reloads" option
722
+ // and now the state is imported during reload.
723
+ // Because of option 2, we need to give possible
724
+ // lazy loaded reducers time to instantiate.
725
+ // As soon as there is no UPDATE action within 1 second,
726
+ // it is assumed that all reducers are loaded.
727
+ return this.dispatcher.pipe(filter((action) => action.type === UPDATE), timeout(1000), debounceTime(1000), map(() => action), catchError(() => of(action)), take(1));
728
+ }
729
+ else {
730
+ return of(action);
731
+ }
732
+ }));
733
+ // Listen for unlifted actions
734
+ const actions$ = changes$.pipe(filter((change) => change.type === ExtensionActionTypes.ACTION), map((change) => this.unwrapAction(change.payload)));
735
+ const actionsUntilStop$ = actions$.pipe(takeUntil(stop$));
736
+ const liftedUntilStop$ = liftedActions$.pipe(takeUntil(stop$));
737
+ this.start$ = start$.pipe(takeUntil(stop$));
738
+ // Only take the action sources between the start/stop events
739
+ this.actions$ = this.start$.pipe(switchMap(() => actionsUntilStop$));
740
+ this.liftedActions$ = this.start$.pipe(switchMap(() => liftedUntilStop$));
741
+ }
742
+ unwrapAction(action) {
743
+ return typeof action === 'string' ? eval(`(${action})`) : action;
744
+ }
745
+ getExtensionConfig(config) {
746
+ var _a;
747
+ const extensionOptions = {
748
+ name: config.name,
749
+ features: config.features,
750
+ serialize: config.serialize,
751
+ autoPause: (_a = config.autoPause) !== null && _a !== void 0 ? _a : false,
752
+ // The action/state sanitizers are not added to the config
753
+ // because sanitation is done in this class already.
754
+ // It is done before sending it to the devtools extension for consistency:
755
+ // - If we call extensionConnection.send(...),
756
+ // the extension would call the sanitizers.
757
+ // - If we call devtoolsExtension.send(...) (aka full state update),
758
+ // the extension would NOT call the sanitizers, so we have to do it ourselves.
759
+ };
760
+ if (config.maxAge !== false /* support === 0 */) {
761
+ extensionOptions.maxAge = config.maxAge;
762
+ }
763
+ return extensionOptions;
764
+ }
765
+ sendToReduxDevtools(send) {
766
+ try {
767
+ send();
768
+ }
769
+ catch (err) {
770
+ console.warn('@ngrx/store-devtools: something went wrong inside the redux devtools', err);
771
+ }
772
+ }
773
+ }
774
+ /** @nocollapse */ /** @nocollapse */ DevtoolsExtension.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: DevtoolsExtension, deps: [{ token: REDUX_DEVTOOLS_EXTENSION }, { token: STORE_DEVTOOLS_CONFIG }, { token: DevtoolsDispatcher }], target: i0.ɵɵFactoryTarget.Injectable });
775
+ /** @nocollapse */ /** @nocollapse */ DevtoolsExtension.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: DevtoolsExtension });
776
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: DevtoolsExtension, decorators: [{
777
+ type: Injectable
778
+ }], ctorParameters: function () {
779
+ return [{ type: undefined, decorators: [{
780
+ type: Inject,
781
+ args: [REDUX_DEVTOOLS_EXTENSION]
782
+ }] }, { type: StoreDevtoolsConfig, decorators: [{
783
+ type: Inject,
784
+ args: [STORE_DEVTOOLS_CONFIG]
785
+ }] }, { type: DevtoolsDispatcher }];
786
+ } });
787
+
788
+ class StoreDevtools {
789
+ constructor(dispatcher, actions$, reducers$, extension, scannedActions, errorHandler, initialState, config) {
790
+ const liftedInitialState = liftInitialState(initialState, config.monitor);
791
+ const liftReducer = liftReducerWith(initialState, liftedInitialState, errorHandler, config.monitor, config);
792
+ const liftedAction$ = merge(merge(actions$.asObservable().pipe(skip(1)), extension.actions$).pipe(map(liftAction)), dispatcher, extension.liftedActions$).pipe(observeOn(queueScheduler));
793
+ const liftedReducer$ = reducers$.pipe(map(liftReducer));
794
+ const liftedStateSubject = new ReplaySubject(1);
795
+ const liftedStateSubscription = liftedAction$
796
+ .pipe(withLatestFrom(liftedReducer$), scan(({ state: liftedState }, [action, reducer]) => {
797
+ let reducedLiftedState = reducer(liftedState, action);
798
+ // On full state update
799
+ // If we have actions filters, we must filter completely our lifted state to be sync with the extension
800
+ if (action.type !== PERFORM_ACTION && shouldFilterActions(config)) {
801
+ reducedLiftedState = filterLiftedState(reducedLiftedState, config.predicate, config.actionsSafelist, config.actionsBlocklist);
802
+ }
803
+ // Extension should be sent the sanitized lifted state
804
+ extension.notify(action, reducedLiftedState);
805
+ return { state: reducedLiftedState, action };
806
+ }, { state: liftedInitialState, action: null }))
807
+ .subscribe(({ state, action }) => {
808
+ liftedStateSubject.next(state);
809
+ if (action.type === PERFORM_ACTION) {
810
+ const unliftedAction = action.action;
811
+ scannedActions.next(unliftedAction);
812
+ }
813
+ });
814
+ const extensionStartSubscription = extension.start$.subscribe(() => {
815
+ this.refresh();
816
+ });
817
+ const liftedState$ = liftedStateSubject.asObservable();
818
+ const state$ = liftedState$.pipe(map(unliftState));
819
+ this.extensionStartSubscription = extensionStartSubscription;
820
+ this.stateSubscription = liftedStateSubscription;
821
+ this.dispatcher = dispatcher;
822
+ this.liftedState = liftedState$;
823
+ this.state = state$;
824
+ }
825
+ dispatch(action) {
826
+ this.dispatcher.next(action);
827
+ }
828
+ next(action) {
829
+ this.dispatcher.next(action);
830
+ }
831
+ error(error) { }
832
+ complete() { }
833
+ performAction(action) {
834
+ this.dispatch(new PerformAction(action, +Date.now()));
835
+ }
836
+ refresh() {
837
+ this.dispatch(new Refresh());
838
+ }
839
+ reset() {
840
+ this.dispatch(new Reset(+Date.now()));
841
+ }
842
+ rollback() {
843
+ this.dispatch(new Rollback(+Date.now()));
844
+ }
845
+ commit() {
846
+ this.dispatch(new Commit(+Date.now()));
847
+ }
848
+ sweep() {
849
+ this.dispatch(new Sweep());
850
+ }
851
+ toggleAction(id) {
852
+ this.dispatch(new ToggleAction(id));
853
+ }
854
+ jumpToAction(actionId) {
855
+ this.dispatch(new JumpToAction(actionId));
856
+ }
857
+ jumpToState(index) {
858
+ this.dispatch(new JumpToState(index));
859
+ }
860
+ importState(nextLiftedState) {
861
+ this.dispatch(new ImportState(nextLiftedState));
862
+ }
863
+ lockChanges(status) {
864
+ this.dispatch(new LockChanges(status));
865
+ }
866
+ pauseRecording(status) {
867
+ this.dispatch(new PauseRecording(status));
868
+ }
869
+ }
870
+ /** @nocollapse */ /** @nocollapse */ StoreDevtools.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: StoreDevtools, deps: [{ token: DevtoolsDispatcher }, { token: i2.ActionsSubject }, { token: i2.ReducerObservable }, { token: DevtoolsExtension }, { token: i2.ScannedActionsSubject }, { token: i0.ErrorHandler }, { token: INITIAL_STATE }, { token: STORE_DEVTOOLS_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
871
+ /** @nocollapse */ /** @nocollapse */ StoreDevtools.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: StoreDevtools });
872
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: StoreDevtools, decorators: [{
873
+ type: Injectable
874
+ }], ctorParameters: function () {
875
+ return [{ type: DevtoolsDispatcher }, { type: i2.ActionsSubject }, { type: i2.ReducerObservable }, { type: DevtoolsExtension }, { type: i2.ScannedActionsSubject }, { type: i0.ErrorHandler }, { type: undefined, decorators: [{
876
+ type: Inject,
877
+ args: [INITIAL_STATE]
878
+ }] }, { type: StoreDevtoolsConfig, decorators: [{
879
+ type: Inject,
880
+ args: [STORE_DEVTOOLS_CONFIG]
881
+ }] }];
882
+ } });
883
+
884
+ const IS_EXTENSION_OR_MONITOR_PRESENT = new InjectionToken('@ngrx/store-devtools Is Devtools Extension or Monitor Present');
885
+ function createIsExtensionOrMonitorPresent(extension, config) {
886
+ return Boolean(extension) || config.monitor !== noMonitor;
887
+ }
888
+ function createReduxDevtoolsExtension() {
889
+ const extensionKey = '__REDUX_DEVTOOLS_EXTENSION__';
890
+ if (typeof window === 'object' &&
891
+ typeof window[extensionKey] !== 'undefined') {
892
+ return window[extensionKey];
893
+ }
894
+ else {
895
+ return null;
896
+ }
897
+ }
898
+ function createStateObservable(devtools) {
899
+ return devtools.state;
900
+ }
901
+ class StoreDevtoolsModule {
902
+ static instrument(options = {}) {
903
+ return {
904
+ ngModule: StoreDevtoolsModule,
905
+ providers: [
906
+ DevtoolsExtension,
907
+ DevtoolsDispatcher,
908
+ StoreDevtools,
909
+ {
910
+ provide: INITIAL_OPTIONS,
911
+ useValue: options,
912
+ },
913
+ {
914
+ provide: IS_EXTENSION_OR_MONITOR_PRESENT,
915
+ deps: [REDUX_DEVTOOLS_EXTENSION, STORE_DEVTOOLS_CONFIG],
916
+ useFactory: createIsExtensionOrMonitorPresent,
917
+ },
918
+ {
919
+ provide: REDUX_DEVTOOLS_EXTENSION,
920
+ useFactory: createReduxDevtoolsExtension,
921
+ },
922
+ {
923
+ provide: STORE_DEVTOOLS_CONFIG,
924
+ deps: [INITIAL_OPTIONS],
925
+ useFactory: createConfig,
926
+ },
927
+ {
928
+ provide: StateObservable,
929
+ deps: [StoreDevtools],
930
+ useFactory: createStateObservable,
931
+ },
932
+ {
933
+ provide: ReducerManagerDispatcher,
934
+ useExisting: DevtoolsDispatcher,
935
+ },
936
+ ],
937
+ };
938
+ }
939
+ }
940
+ /** @nocollapse */ /** @nocollapse */ StoreDevtoolsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: StoreDevtoolsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
941
+ /** @nocollapse */ /** @nocollapse */ StoreDevtoolsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: StoreDevtoolsModule });
942
+ /** @nocollapse */ /** @nocollapse */ StoreDevtoolsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: StoreDevtoolsModule });
943
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: StoreDevtoolsModule, decorators: [{
944
+ type: NgModule,
945
+ args: [{}]
946
+ }] });
947
+
948
+ /**
949
+ * DO NOT EDIT
950
+ *
951
+ * This file is automatically generated at build
952
+ */
953
+
954
+ /**
955
+ * Generated bundle index. Do not edit.
956
+ */
957
+
958
+ export { INITIAL_OPTIONS, RECOMPUTE, StoreDevtools, StoreDevtoolsConfig, StoreDevtoolsModule };
959
+ //# sourceMappingURL=ngrx-store-devtools.mjs.map