@ngxs/devtools-plugin 3.7.2 → 3.7.3-dev.master-8834f50

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.
@@ -1,299 +1,357 @@
1
- import { InjectionToken, Injectable, Inject, Injector, NgModule } from '@angular/core';
1
+ import { InjectionToken, ɵglobal, Injectable, Inject, Injector, NgZone, NgModule } from '@angular/core';
2
2
  import { Store, getActionTypeFromInstance, NGXS_PLUGINS } from '@ngxs/store';
3
3
  import { catchError, tap } from 'rxjs/operators';
4
4
 
5
- /**
6
- * @fileoverview added by tsickle
7
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
8
- */
9
- /**
10
- * Interface for the redux-devtools-extension API.
11
- * @record
12
- */
13
- function NgxsDevtoolsExtension() { }
14
- if (false) {
15
- /**
16
- * @param {?} state
17
- * @return {?}
18
- */
19
- NgxsDevtoolsExtension.prototype.init = function (state) { };
20
- /**
21
- * @param {?} action
22
- * @param {?=} state
23
- * @return {?}
24
- */
25
- NgxsDevtoolsExtension.prototype.send = function (action, state) { };
26
- /**
27
- * @param {?} fn
28
- * @return {?}
29
- */
30
- NgxsDevtoolsExtension.prototype.subscribe = function (fn) { };
31
- }
32
- /**
33
- * @record
34
- */
35
- function NgxsDevtoolsAction() { }
36
- if (false) {
37
- /** @type {?} */
38
- NgxsDevtoolsAction.prototype.type;
39
- /** @type {?} */
40
- NgxsDevtoolsAction.prototype.payload;
41
- /** @type {?} */
42
- NgxsDevtoolsAction.prototype.state;
43
- /** @type {?} */
44
- NgxsDevtoolsAction.prototype.id;
45
- /** @type {?} */
46
- NgxsDevtoolsAction.prototype.source;
47
- }
48
- /**
49
- * @record
50
- */
51
- function NgxsDevtoolsOptions() { }
52
- if (false) {
53
- /**
54
- * The name of the extension
55
- * @type {?|undefined}
56
- */
57
- NgxsDevtoolsOptions.prototype.name;
58
- /**
59
- * Whether the dev tools is enabled or note. Useful for setting during production.
60
- * @type {?|undefined}
61
- */
62
- NgxsDevtoolsOptions.prototype.disabled;
63
- /**
64
- * Max number of entiries to keep.
65
- * @type {?|undefined}
66
- */
67
- NgxsDevtoolsOptions.prototype.maxAge;
68
- /**
69
- * Reformat actions before sending to dev tools
70
- * @type {?|undefined}
71
- */
72
- NgxsDevtoolsOptions.prototype.actionSanitizer;
73
- /**
74
- * Reformat state before sending to devtools
75
- * @type {?|undefined}
76
- */
77
- NgxsDevtoolsOptions.prototype.stateSanitizer;
78
- }
79
- /** @type {?} */
5
+ /**
6
+ * @fileoverview added by tsickle
7
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
8
+ */
9
+ /**
10
+ * Interface for the redux-devtools-extension API.
11
+ * @record
12
+ */
13
+ function NgxsDevtoolsExtension() { }
14
+ if (false) {
15
+ /**
16
+ * @param {?} state
17
+ * @return {?}
18
+ */
19
+ NgxsDevtoolsExtension.prototype.init = function (state) { };
20
+ /**
21
+ * @param {?} action
22
+ * @param {?=} state
23
+ * @return {?}
24
+ */
25
+ NgxsDevtoolsExtension.prototype.send = function (action, state) { };
26
+ /**
27
+ * @param {?} fn
28
+ * @return {?}
29
+ */
30
+ NgxsDevtoolsExtension.prototype.subscribe = function (fn) { };
31
+ }
32
+ /**
33
+ * @record
34
+ */
35
+ function NgxsDevtoolsAction() { }
36
+ if (false) {
37
+ /** @type {?} */
38
+ NgxsDevtoolsAction.prototype.type;
39
+ /** @type {?} */
40
+ NgxsDevtoolsAction.prototype.payload;
41
+ /** @type {?} */
42
+ NgxsDevtoolsAction.prototype.state;
43
+ /** @type {?} */
44
+ NgxsDevtoolsAction.prototype.id;
45
+ /** @type {?} */
46
+ NgxsDevtoolsAction.prototype.source;
47
+ }
48
+ /**
49
+ * @record
50
+ */
51
+ function NgxsDevtoolsOptions() { }
52
+ if (false) {
53
+ /**
54
+ * The name of the extension
55
+ * @type {?|undefined}
56
+ */
57
+ NgxsDevtoolsOptions.prototype.name;
58
+ /**
59
+ * Whether the dev tools is enabled or note. Useful for setting during production.
60
+ * @type {?|undefined}
61
+ */
62
+ NgxsDevtoolsOptions.prototype.disabled;
63
+ /**
64
+ * Max number of entiries to keep.
65
+ * @type {?|undefined}
66
+ */
67
+ NgxsDevtoolsOptions.prototype.maxAge;
68
+ /**
69
+ * Reformat actions before sending to dev tools
70
+ * @type {?|undefined}
71
+ */
72
+ NgxsDevtoolsOptions.prototype.actionSanitizer;
73
+ /**
74
+ * Reformat state before sending to devtools
75
+ * @type {?|undefined}
76
+ */
77
+ NgxsDevtoolsOptions.prototype.stateSanitizer;
78
+ }
79
+ /** @type {?} */
80
80
  const NGXS_DEVTOOLS_OPTIONS = new InjectionToken('NGXS_DEVTOOLS_OPTIONS');
81
81
 
82
- /**
83
- * @fileoverview added by tsickle
84
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
85
- */
86
- /**
87
- * Adds support for the Redux Devtools extension:
88
- * http://extension.remotedev.io/
89
- */
90
- class NgxsReduxDevtoolsPlugin {
91
- /**
92
- * @param {?} _options
93
- * @param {?} _injector
94
- */
95
- constructor(_options, _injector) {
96
- this._options = _options;
97
- this._injector = _injector;
98
- this.devtoolsExtension = null;
99
- this.windowObj = typeof window !== 'undefined' ? window : {};
100
- /** @type {?} */
101
- const globalDevtools = this.windowObj['__REDUX_DEVTOOLS_EXTENSION__'] || this.windowObj['devToolsExtension'];
102
- if (globalDevtools) {
103
- this.devtoolsExtension = (/** @type {?} */ (globalDevtools.connect(_options)));
104
- this.devtoolsExtension.subscribe((/**
105
- * @param {?} a
106
- * @return {?}
107
- */
108
- a => this.dispatched(a)));
109
- }
110
- }
111
- /**
112
- * Lazy get the store for circular dependency issues
113
- * @private
114
- * @return {?}
115
- */
116
- get store() {
117
- return this._injector.get(Store);
118
- }
119
- /**
120
- * Middleware handle function
121
- * @param {?} state
122
- * @param {?} action
123
- * @param {?} next
124
- * @return {?}
125
- */
126
- handle(state, action, next) {
127
- /** @type {?} */
128
- const isDisabled = this._options && this._options.disabled;
129
- if (!this.devtoolsExtension || isDisabled) {
130
- return next(state, action);
131
- }
132
- return next(state, action).pipe(catchError((/**
133
- * @param {?} error
134
- * @return {?}
135
- */
136
- error => {
137
- /** @type {?} */
138
- const newState = this.store.snapshot();
139
- this.sendToDevTools(state, action, newState);
140
- throw error;
141
- })), tap((/**
142
- * @param {?} newState
143
- * @return {?}
144
- */
145
- newState => {
146
- this.sendToDevTools(state, action, newState);
147
- })));
148
- }
149
- /**
150
- * @private
151
- * @param {?} state
152
- * @param {?} action
153
- * @param {?} newState
154
- * @return {?}
155
- */
156
- sendToDevTools(state, action, newState) {
157
- /** @type {?} */
158
- const type = getActionTypeFromInstance(action);
159
- // if init action, send initial state to dev tools
160
- /** @type {?} */
161
- const isInitAction = type === '@@INIT';
162
- if (isInitAction) {
163
- (/** @type {?} */ (this.devtoolsExtension)).init(state);
164
- }
165
- else {
166
- (/** @type {?} */ (this.devtoolsExtension)).send(Object.assign({}, action, { action: null, type }), newState);
167
- }
168
- }
169
- /**
170
- * Handle the action from the dev tools subscription
171
- * @param {?} action
172
- * @return {?}
173
- */
174
- dispatched(action) {
175
- if (action.type === 'DISPATCH') {
176
- if (action.payload.type === 'JUMP_TO_ACTION' ||
177
- action.payload.type === 'JUMP_TO_STATE') {
178
- /** @type {?} */
179
- const prevState = JSON.parse(action.state);
180
- this.store.reset(prevState);
181
- }
182
- else if (action.payload.type === 'TOGGLE_ACTION') {
183
- console.warn('Skip is not supported at this time.');
184
- }
185
- else if (action.payload.type === 'IMPORT_STATE') {
186
- const { actionsById, computedStates, currentStateIndex } = action.payload.nextLiftedState;
187
- (/** @type {?} */ (this.devtoolsExtension)).init(computedStates[0].state);
188
- Object.keys(actionsById)
189
- .filter((/**
190
- * @param {?} actionId
191
- * @return {?}
192
- */
193
- actionId => actionId !== '0'))
194
- .forEach((/**
195
- * @param {?} actionId
196
- * @return {?}
197
- */
198
- actionId => (/** @type {?} */ (this.devtoolsExtension)).send(actionsById[actionId], computedStates[actionId].state)));
199
- this.store.reset(computedStates[currentStateIndex].state);
200
- }
201
- }
202
- else if (action.type === 'ACTION') {
203
- /** @type {?} */
204
- const actionPayload = JSON.parse(action.payload);
205
- this.store.dispatch(actionPayload);
206
- }
207
- }
208
- }
209
- NgxsReduxDevtoolsPlugin.decorators = [
210
- { type: Injectable }
211
- ];
212
- /** @nocollapse */
213
- NgxsReduxDevtoolsPlugin.ctorParameters = () => [
214
- { type: undefined, decorators: [{ type: Inject, args: [NGXS_DEVTOOLS_OPTIONS,] }] },
215
- { type: Injector }
216
- ];
217
- if (false) {
218
- /**
219
- * @type {?}
220
- * @private
221
- */
222
- NgxsReduxDevtoolsPlugin.prototype.devtoolsExtension;
223
- /**
224
- * @type {?}
225
- * @private
226
- */
227
- NgxsReduxDevtoolsPlugin.prototype.windowObj;
228
- /**
229
- * @type {?}
230
- * @private
231
- */
232
- NgxsReduxDevtoolsPlugin.prototype._options;
233
- /**
234
- * @type {?}
235
- * @private
236
- */
237
- NgxsReduxDevtoolsPlugin.prototype._injector;
82
+ /**
83
+ * @fileoverview added by tsickle
84
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
85
+ */
86
+ /** @enum {string} */
87
+ const ReduxDevtoolsActionType = {
88
+ Dispatch: 'DISPATCH',
89
+ Action: 'ACTION',
90
+ };
91
+ /** @enum {string} */
92
+ const ReduxDevtoolsPayloadType = {
93
+ JumpToAction: 'JUMP_TO_ACTION',
94
+ JumpToState: 'JUMP_TO_STATE',
95
+ ToggleAction: 'TOGGLE_ACTION',
96
+ ImportState: 'IMPORT_STATE',
97
+ };
98
+ /**
99
+ * Adds support for the Redux Devtools extension:
100
+ * http://extension.remotedev.io/
101
+ */
102
+ class NgxsReduxDevtoolsPlugin {
103
+ /**
104
+ * @param {?} _options
105
+ * @param {?} _injector
106
+ * @param {?} _ngZone
107
+ */
108
+ constructor(_options, _injector, _ngZone) {
109
+ this._options = _options;
110
+ this._injector = _injector;
111
+ this._ngZone = _ngZone;
112
+ this.devtoolsExtension = null;
113
+ this.globalDevtools = ɵglobal['__REDUX_DEVTOOLS_EXTENSION__'] || ɵglobal['devToolsExtension'];
114
+ this.unsubscribe = null;
115
+ this.connect();
116
+ }
117
+ /**
118
+ * @return {?}
119
+ */
120
+ ngOnDestroy() {
121
+ if (this.unsubscribe !== null) {
122
+ this.unsubscribe();
123
+ }
124
+ if (this.globalDevtools) {
125
+ this.globalDevtools.disconnect();
126
+ }
127
+ }
128
+ /**
129
+ * Lazy get the store for circular dependency issues
130
+ * @private
131
+ * @return {?}
132
+ */
133
+ get store() {
134
+ return this._injector.get(Store);
135
+ }
136
+ /**
137
+ * Middleware handle function
138
+ * @param {?} state
139
+ * @param {?} action
140
+ * @param {?} next
141
+ * @return {?}
142
+ */
143
+ handle(state, action, next) {
144
+ if (!this.devtoolsExtension || this._options.disabled) {
145
+ return next(state, action);
146
+ }
147
+ return next(state, action).pipe(catchError((/**
148
+ * @param {?} error
149
+ * @return {?}
150
+ */
151
+ error => {
152
+ /** @type {?} */
153
+ const newState = this.store.snapshot();
154
+ this.sendToDevTools(state, action, newState);
155
+ throw error;
156
+ })), tap((/**
157
+ * @param {?} newState
158
+ * @return {?}
159
+ */
160
+ newState => {
161
+ this.sendToDevTools(state, action, newState);
162
+ })));
163
+ }
164
+ /**
165
+ * @private
166
+ * @param {?} state
167
+ * @param {?} action
168
+ * @param {?} newState
169
+ * @return {?}
170
+ */
171
+ sendToDevTools(state, action, newState) {
172
+ /** @type {?} */
173
+ const type = getActionTypeFromInstance(action);
174
+ // if init action, send initial state to dev tools
175
+ /** @type {?} */
176
+ const isInitAction = type === '@@INIT';
177
+ if (isInitAction) {
178
+ (/** @type {?} */ (this.devtoolsExtension)).init(state);
179
+ }
180
+ else {
181
+ (/** @type {?} */ (this.devtoolsExtension)).send(Object.assign({}, action, { action: null, type }), newState);
182
+ }
183
+ }
184
+ /**
185
+ * Handle the action from the dev tools subscription
186
+ * @param {?} action
187
+ * @return {?}
188
+ */
189
+ dispatched(action) {
190
+ if (action.type === "DISPATCH" /* Dispatch */) {
191
+ if (action.payload.type === "JUMP_TO_ACTION" /* JumpToAction */ ||
192
+ action.payload.type === "JUMP_TO_STATE" /* JumpToState */) {
193
+ /** @type {?} */
194
+ const prevState = JSON.parse(action.state);
195
+ this.store.reset(prevState);
196
+ }
197
+ else if (action.payload.type === "TOGGLE_ACTION" /* ToggleAction */) {
198
+ console.warn('Skip is not supported at this time.');
199
+ }
200
+ else if (action.payload.type === "IMPORT_STATE" /* ImportState */) {
201
+ const { actionsById, computedStates, currentStateIndex } = action.payload.nextLiftedState;
202
+ (/** @type {?} */ (this.devtoolsExtension)).init(computedStates[0].state);
203
+ Object.keys(actionsById)
204
+ .filter((/**
205
+ * @param {?} actionId
206
+ * @return {?}
207
+ */
208
+ actionId => actionId !== '0'))
209
+ .forEach((/**
210
+ * @param {?} actionId
211
+ * @return {?}
212
+ */
213
+ actionId => (/** @type {?} */ (this.devtoolsExtension)).send(actionsById[actionId], computedStates[actionId].state)));
214
+ this.store.reset(computedStates[currentStateIndex].state);
215
+ }
216
+ }
217
+ else if (action.type === "ACTION" /* Action */) {
218
+ /** @type {?} */
219
+ const actionPayload = JSON.parse(action.payload);
220
+ this.store.dispatch(actionPayload);
221
+ }
222
+ }
223
+ /**
224
+ * @private
225
+ * @return {?}
226
+ */
227
+ connect() {
228
+ if (!this.globalDevtools || this._options.disabled) {
229
+ return;
230
+ }
231
+ // The `connect` method adds `message` event listener since it communicates
232
+ // with an extension through `window.postMessage` and message events.
233
+ // We handle only 2 events; thus, we don't want to run many change detections
234
+ // because the extension sends events that we don't have to handle.
235
+ this.devtoolsExtension = this._ngZone.runOutsideAngular((/**
236
+ * @return {?}
237
+ */
238
+ () => (/** @type {?} */ (this.globalDevtools.connect(this._options)))));
239
+ this.unsubscribe = this.devtoolsExtension.subscribe((/**
240
+ * @param {?} action
241
+ * @return {?}
242
+ */
243
+ action => {
244
+ if (action.type === "DISPATCH" /* Dispatch */ ||
245
+ action.type === "ACTION" /* Action */) {
246
+ this._ngZone.run((/**
247
+ * @return {?}
248
+ */
249
+ () => {
250
+ this.dispatched(action);
251
+ }));
252
+ }
253
+ }));
254
+ }
255
+ }
256
+ NgxsReduxDevtoolsPlugin.decorators = [
257
+ { type: Injectable }
258
+ ];
259
+ /** @nocollapse */
260
+ NgxsReduxDevtoolsPlugin.ctorParameters = () => [
261
+ { type: undefined, decorators: [{ type: Inject, args: [NGXS_DEVTOOLS_OPTIONS,] }] },
262
+ { type: Injector },
263
+ { type: NgZone }
264
+ ];
265
+ if (false) {
266
+ /**
267
+ * @type {?}
268
+ * @private
269
+ */
270
+ NgxsReduxDevtoolsPlugin.prototype.devtoolsExtension;
271
+ /**
272
+ * @type {?}
273
+ * @private
274
+ */
275
+ NgxsReduxDevtoolsPlugin.prototype.globalDevtools;
276
+ /**
277
+ * @type {?}
278
+ * @private
279
+ */
280
+ NgxsReduxDevtoolsPlugin.prototype.unsubscribe;
281
+ /**
282
+ * @type {?}
283
+ * @private
284
+ */
285
+ NgxsReduxDevtoolsPlugin.prototype._options;
286
+ /**
287
+ * @type {?}
288
+ * @private
289
+ */
290
+ NgxsReduxDevtoolsPlugin.prototype._injector;
291
+ /**
292
+ * @type {?}
293
+ * @private
294
+ */
295
+ NgxsReduxDevtoolsPlugin.prototype._ngZone;
238
296
  }
239
297
 
240
- /**
241
- * @fileoverview added by tsickle
242
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
243
- */
244
- /**
245
- * @param {?} options
246
- * @return {?}
247
- */
248
- function devtoolsOptionsFactory(options) {
249
- return Object.assign({ name: 'NGXS' }, options);
250
- }
251
- /** @type {?} */
252
- const USER_OPTIONS = new InjectionToken('USER_OPTIONS');
253
- class NgxsReduxDevtoolsPluginModule {
254
- /**
255
- * @param {?=} options
256
- * @return {?}
257
- */
258
- static forRoot(options) {
259
- return {
260
- ngModule: NgxsReduxDevtoolsPluginModule,
261
- providers: [
262
- {
263
- provide: NGXS_PLUGINS,
264
- useClass: NgxsReduxDevtoolsPlugin,
265
- multi: true
266
- },
267
- {
268
- provide: USER_OPTIONS,
269
- useValue: options
270
- },
271
- {
272
- provide: NGXS_DEVTOOLS_OPTIONS,
273
- useFactory: devtoolsOptionsFactory,
274
- deps: [USER_OPTIONS]
275
- }
276
- ]
277
- };
278
- }
279
- }
280
- NgxsReduxDevtoolsPluginModule.decorators = [
281
- { type: NgModule }
298
+ /**
299
+ * @fileoverview added by tsickle
300
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
301
+ */
302
+ /**
303
+ * @param {?} options
304
+ * @return {?}
305
+ */
306
+ function devtoolsOptionsFactory(options) {
307
+ return Object.assign({ name: 'NGXS' }, options);
308
+ }
309
+ /** @type {?} */
310
+ const USER_OPTIONS = new InjectionToken('USER_OPTIONS');
311
+ class NgxsReduxDevtoolsPluginModule {
312
+ /**
313
+ * @param {?=} options
314
+ * @return {?}
315
+ */
316
+ static forRoot(options) {
317
+ return {
318
+ ngModule: NgxsReduxDevtoolsPluginModule,
319
+ providers: [
320
+ {
321
+ provide: NGXS_PLUGINS,
322
+ useClass: NgxsReduxDevtoolsPlugin,
323
+ multi: true
324
+ },
325
+ {
326
+ provide: USER_OPTIONS,
327
+ useValue: options
328
+ },
329
+ {
330
+ provide: NGXS_DEVTOOLS_OPTIONS,
331
+ useFactory: devtoolsOptionsFactory,
332
+ deps: [USER_OPTIONS]
333
+ }
334
+ ]
335
+ };
336
+ }
337
+ }
338
+ NgxsReduxDevtoolsPluginModule.decorators = [
339
+ { type: NgModule }
282
340
  ];
283
341
 
284
- /**
285
- * @fileoverview added by tsickle
286
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
342
+ /**
343
+ * @fileoverview added by tsickle
344
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
287
345
  */
288
346
 
289
- /**
290
- * @fileoverview added by tsickle
291
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
347
+ /**
348
+ * @fileoverview added by tsickle
349
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
292
350
  */
293
351
 
294
- /**
295
- * @fileoverview added by tsickle
296
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
352
+ /**
353
+ * @fileoverview added by tsickle
354
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
297
355
  */
298
356
 
299
357
  export { NGXS_DEVTOOLS_OPTIONS, NgxsReduxDevtoolsPlugin, NgxsReduxDevtoolsPluginModule, devtoolsOptionsFactory as ɵa, USER_OPTIONS as ɵb };