@ngxs/router-plugin 3.7.6 → 3.8.0-dev.master-c341c15

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,778 +0,0 @@
1
- import { NgZone, Injectable, NgModule } from '@angular/core';
2
- import { Store, Action, Selector, State, NgxsModule } from '@ngxs/store';
3
- import { __assign, __decorate, __metadata } from 'tslib';
4
- import { NavigationStart, RoutesRecognized, ResolveEnd, NavigationCancel, NavigationError, NavigationEnd, Router } from '@angular/router';
5
- import { Subscription } from 'rxjs';
6
-
7
- /**
8
- * @fileoverview added by tsickle
9
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
10
- */
11
- /**
12
- * Public event api of the router
13
- */
14
- var /**
15
- * Public event api of the router
16
- */
17
- Navigate = /** @class */ (function () {
18
- function Navigate(path, queryParams, extras) {
19
- this.path = path;
20
- this.queryParams = queryParams;
21
- this.extras = extras;
22
- }
23
- Object.defineProperty(Navigate, "type", {
24
- get: /**
25
- * @return {?}
26
- */
27
- 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 '[Router] Navigate';
30
- },
31
- enumerable: true,
32
- configurable: true
33
- });
34
- return Navigate;
35
- }());
36
- if (false) {
37
- /** @type {?} */
38
- Navigate.prototype.path;
39
- /** @type {?} */
40
- Navigate.prototype.queryParams;
41
- /** @type {?} */
42
- Navigate.prototype.extras;
43
- }
44
- /**
45
- *
46
- * Angular Routers internal state events
47
- *
48
- */
49
- /**
50
- * An action dispatched when the router navigates.
51
- * @template T
52
- */
53
- var /**
54
- *
55
- * Angular Routers internal state events
56
- *
57
- */
58
- /**
59
- * An action dispatched when the router navigates.
60
- * @template T
61
- */
62
- RouterNavigation = /** @class */ (function () {
63
- function RouterNavigation(routerState, event, trigger) {
64
- if (trigger === void 0) { trigger = 'none'; }
65
- this.routerState = routerState;
66
- this.event = event;
67
- this.trigger = trigger;
68
- }
69
- Object.defineProperty(RouterNavigation, "type", {
70
- get: /**
71
- * @return {?}
72
- */
73
- function () {
74
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
75
- return '[Router] RouterNavigation';
76
- },
77
- enumerable: true,
78
- configurable: true
79
- });
80
- return RouterNavigation;
81
- }());
82
- if (false) {
83
- /** @type {?} */
84
- RouterNavigation.prototype.routerState;
85
- /** @type {?} */
86
- RouterNavigation.prototype.event;
87
- /** @type {?} */
88
- RouterNavigation.prototype.trigger;
89
- }
90
- /**
91
- * An action dispatched when the router cancel navigation.
92
- * @template T, V
93
- */
94
- var /**
95
- * An action dispatched when the router cancel navigation.
96
- * @template T, V
97
- */
98
- RouterCancel = /** @class */ (function () {
99
- function RouterCancel(routerState, storeState, event, trigger) {
100
- if (trigger === void 0) { trigger = 'none'; }
101
- this.routerState = routerState;
102
- this.storeState = storeState;
103
- this.event = event;
104
- this.trigger = trigger;
105
- }
106
- Object.defineProperty(RouterCancel, "type", {
107
- get: /**
108
- * @return {?}
109
- */
110
- function () {
111
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
112
- return '[Router] RouterCancel';
113
- },
114
- enumerable: true,
115
- configurable: true
116
- });
117
- return RouterCancel;
118
- }());
119
- if (false) {
120
- /** @type {?} */
121
- RouterCancel.prototype.routerState;
122
- /** @type {?} */
123
- RouterCancel.prototype.storeState;
124
- /** @type {?} */
125
- RouterCancel.prototype.event;
126
- /** @type {?} */
127
- RouterCancel.prototype.trigger;
128
- }
129
- /**
130
- * An action dispatched when the router errors.
131
- * @template T, V
132
- */
133
- var /**
134
- * An action dispatched when the router errors.
135
- * @template T, V
136
- */
137
- RouterError = /** @class */ (function () {
138
- function RouterError(routerState, storeState, event, trigger) {
139
- if (trigger === void 0) { trigger = 'none'; }
140
- this.routerState = routerState;
141
- this.storeState = storeState;
142
- this.event = event;
143
- this.trigger = trigger;
144
- }
145
- Object.defineProperty(RouterError, "type", {
146
- get: /**
147
- * @return {?}
148
- */
149
- function () {
150
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
151
- return '[Router] RouterError';
152
- },
153
- enumerable: true,
154
- configurable: true
155
- });
156
- return RouterError;
157
- }());
158
- if (false) {
159
- /** @type {?} */
160
- RouterError.prototype.routerState;
161
- /** @type {?} */
162
- RouterError.prototype.storeState;
163
- /** @type {?} */
164
- RouterError.prototype.event;
165
- /** @type {?} */
166
- RouterError.prototype.trigger;
167
- }
168
- /**
169
- * An action dispatched when the `ResolveEnd` event is triggered.
170
- * @template T
171
- */
172
- var /**
173
- * An action dispatched when the `ResolveEnd` event is triggered.
174
- * @template T
175
- */
176
- RouterDataResolved = /** @class */ (function () {
177
- function RouterDataResolved(routerState, event, trigger) {
178
- if (trigger === void 0) { trigger = 'none'; }
179
- this.routerState = routerState;
180
- this.event = event;
181
- this.trigger = trigger;
182
- }
183
- Object.defineProperty(RouterDataResolved, "type", {
184
- get: /**
185
- * @return {?}
186
- */
187
- function () {
188
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
189
- return '[Router] RouterDataResolved';
190
- },
191
- enumerable: true,
192
- configurable: true
193
- });
194
- return RouterDataResolved;
195
- }());
196
- if (false) {
197
- /** @type {?} */
198
- RouterDataResolved.prototype.routerState;
199
- /** @type {?} */
200
- RouterDataResolved.prototype.event;
201
- /** @type {?} */
202
- RouterDataResolved.prototype.trigger;
203
- }
204
-
205
- /**
206
- * @fileoverview added by tsickle
207
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
208
- */
209
- /**
210
- * @abstract
211
- * @template T
212
- */
213
- var /**
214
- * @abstract
215
- * @template T
216
- */
217
- RouterStateSerializer = /** @class */ (function () {
218
- function RouterStateSerializer() {
219
- }
220
- return RouterStateSerializer;
221
- }());
222
- if (false) {
223
- /**
224
- * @abstract
225
- * @param {?} routerState
226
- * @return {?}
227
- */
228
- RouterStateSerializer.prototype.serialize = function (routerState) { };
229
- }
230
- /**
231
- * @record
232
- */
233
- function SerializedRouterStateSnapshot() { }
234
- if (false) {
235
- /** @type {?} */
236
- SerializedRouterStateSnapshot.prototype.root;
237
- /** @type {?} */
238
- SerializedRouterStateSnapshot.prototype.url;
239
- }
240
- var DefaultRouterStateSerializer = /** @class */ (function () {
241
- function DefaultRouterStateSerializer() {
242
- }
243
- /**
244
- * @param {?} routerState
245
- * @return {?}
246
- */
247
- DefaultRouterStateSerializer.prototype.serialize = /**
248
- * @param {?} routerState
249
- * @return {?}
250
- */
251
- function (routerState) {
252
- return {
253
- root: this.serializeRoute(routerState.root),
254
- url: routerState.url
255
- };
256
- };
257
- /**
258
- * @private
259
- * @param {?} route
260
- * @return {?}
261
- */
262
- DefaultRouterStateSerializer.prototype.serializeRoute = /**
263
- * @private
264
- * @param {?} route
265
- * @return {?}
266
- */
267
- function (route) {
268
- var _this = this;
269
- /** @type {?} */
270
- var children = route.children.map((/**
271
- * @param {?} c
272
- * @return {?}
273
- */
274
- function (c) { return _this.serializeRoute(c); }));
275
- return {
276
- url: route.url,
277
- params: route.params,
278
- queryParams: route.queryParams,
279
- fragment: route.fragment,
280
- data: route.data,
281
- outlet: route.outlet,
282
- component: null,
283
- routeConfig: null,
284
- root: (/** @type {?} */ (null)),
285
- parent: null,
286
- firstChild: children[0],
287
- children: children,
288
- pathFromRoot: (/** @type {?} */ (null)),
289
- paramMap: route.paramMap,
290
- queryParamMap: route.queryParamMap,
291
- toString: route.toString
292
- };
293
- };
294
- return DefaultRouterStateSerializer;
295
- }());
296
-
297
- /**
298
- * @fileoverview added by tsickle
299
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
300
- */
301
- /**
302
- * @record
303
- * @template T
304
- */
305
- function RouterStateModel() { }
306
- if (false) {
307
- /** @type {?|undefined} */
308
- RouterStateModel.prototype.state;
309
- /** @type {?|undefined} */
310
- RouterStateModel.prototype.navigationId;
311
- /** @type {?} */
312
- RouterStateModel.prototype.trigger;
313
- }
314
- var RouterState = /** @class */ (function () {
315
- function RouterState(_store, _router, _serializer, _ngZone) {
316
- this._store = _store;
317
- this._router = _router;
318
- this._serializer = _serializer;
319
- this._ngZone = _ngZone;
320
- /**
321
- * Determines how navigation was performed by the `RouterState` itself
322
- * or outside via `new Navigate(...)`
323
- */
324
- this._trigger = 'none';
325
- /**
326
- * That's the serialized state from the `Router` class
327
- */
328
- this._routerState = null;
329
- /**
330
- * That's the value of the `RouterState` state
331
- */
332
- this._storeState = null;
333
- this._lastRoutesRecognized = (/** @type {?} */ (null));
334
- this._subscription = new Subscription();
335
- this.setUpStoreListener();
336
- this.setUpRouterEventsListener();
337
- }
338
- RouterState_1 = RouterState;
339
- /**
340
- * @template T
341
- * @param {?} state
342
- * @return {?}
343
- */
344
- RouterState.state = /**
345
- * @template T
346
- * @param {?} state
347
- * @return {?}
348
- */
349
- function (state) {
350
- return state && state.state;
351
- };
352
- /**
353
- * @param {?} state
354
- * @return {?}
355
- */
356
- RouterState.url = /**
357
- * @param {?} state
358
- * @return {?}
359
- */
360
- function (state) {
361
- return state && state.state && state.state.url;
362
- };
363
- /**
364
- * @return {?}
365
- */
366
- RouterState.prototype.ngOnDestroy = /**
367
- * @return {?}
368
- */
369
- function () {
370
- this._subscription.unsubscribe();
371
- };
372
- /**
373
- * @param {?} _
374
- * @param {?} action
375
- * @return {?}
376
- */
377
- RouterState.prototype.navigate = /**
378
- * @param {?} _
379
- * @param {?} action
380
- * @return {?}
381
- */
382
- function (_, action) {
383
- var _this = this;
384
- return this._ngZone.run((/**
385
- * @return {?}
386
- */
387
- function () {
388
- return _this._router.navigate(action.path, __assign({ queryParams: action.queryParams }, action.extras));
389
- }));
390
- };
391
- /**
392
- * @param {?} ctx
393
- * @param {?} action
394
- * @return {?}
395
- */
396
- RouterState.prototype.angularRouterAction = /**
397
- * @param {?} ctx
398
- * @param {?} action
399
- * @return {?}
400
- */
401
- function (ctx, action) {
402
- ctx.setState(__assign({}, ctx.getState(), { trigger: action.trigger, state: action.routerState, navigationId: action.event.id }));
403
- };
404
- /**
405
- * @private
406
- * @return {?}
407
- */
408
- RouterState.prototype.setUpStoreListener = /**
409
- * @private
410
- * @return {?}
411
- */
412
- function () {
413
- var _this = this;
414
- /** @type {?} */
415
- var subscription = this._store
416
- .select(RouterState_1)
417
- .subscribe((/**
418
- * @param {?} state
419
- * @return {?}
420
- */
421
- function (state) {
422
- _this.navigateIfNeeded(state);
423
- }));
424
- this._subscription.add(subscription);
425
- };
426
- /**
427
- * @private
428
- * @return {?}
429
- */
430
- RouterState.prototype.setUpRouterEventsListener = /**
431
- * @private
432
- * @return {?}
433
- */
434
- function () {
435
- var _this = this;
436
- /** @type {?} */
437
- var subscription = this._router.events.subscribe((/**
438
- * @param {?} event
439
- * @return {?}
440
- */
441
- function (event) {
442
- if (event instanceof NavigationStart) {
443
- _this.navigationStart();
444
- }
445
- else if (event instanceof RoutesRecognized) {
446
- _this._lastRoutesRecognized = event;
447
- }
448
- else if (event instanceof ResolveEnd) {
449
- _this.dispatchRouterDataResolved(event);
450
- }
451
- else if (event instanceof NavigationCancel) {
452
- _this.dispatchRouterCancel(event);
453
- _this.reset();
454
- }
455
- else if (event instanceof NavigationError) {
456
- _this.dispatchRouterError(event);
457
- _this.reset();
458
- }
459
- else if (event instanceof NavigationEnd) {
460
- _this.navigationEnd();
461
- _this.reset();
462
- }
463
- }));
464
- this._subscription.add(subscription);
465
- };
466
- /**
467
- * @private
468
- * @return {?}
469
- */
470
- RouterState.prototype.navigationStart = /**
471
- * @private
472
- * @return {?}
473
- */
474
- function () {
475
- this._routerState = this._serializer.serialize(this._router.routerState.snapshot);
476
- if (this._trigger !== 'none') {
477
- this._storeState = this._store.selectSnapshot(RouterState_1);
478
- }
479
- };
480
- /**
481
- * @private
482
- * @return {?}
483
- */
484
- RouterState.prototype.navigationEnd = /**
485
- * @private
486
- * @return {?}
487
- */
488
- function () {
489
- if (this.shouldDispatchRouterNavigation()) {
490
- this.dispatchRouterNavigation();
491
- }
492
- };
493
- /**
494
- * @private
495
- * @return {?}
496
- */
497
- RouterState.prototype.shouldDispatchRouterNavigation = /**
498
- * @private
499
- * @return {?}
500
- */
501
- function () {
502
- if (!this._storeState)
503
- return true;
504
- return this._trigger !== 'store';
505
- };
506
- /**
507
- * @private
508
- * @param {?} state
509
- * @return {?}
510
- */
511
- RouterState.prototype.navigateIfNeeded = /**
512
- * @private
513
- * @param {?} state
514
- * @return {?}
515
- */
516
- function (state) {
517
- var _this = this;
518
- if (state && state.trigger === 'devtools') {
519
- this._storeState = this._store.selectSnapshot(RouterState_1);
520
- }
521
- /** @type {?} */
522
- var canSkipNavigation = !this._storeState ||
523
- !this._storeState.state ||
524
- !state ||
525
- state.trigger === 'router' ||
526
- this._router.url === this._storeState.state.url;
527
- if (canSkipNavigation) {
528
- return;
529
- }
530
- this._trigger = 'store';
531
- this._ngZone.run((/**
532
- * @return {?}
533
- */
534
- function () {
535
- _this._router.navigateByUrl((/** @type {?} */ ((/** @type {?} */ (_this._storeState)).state)).url);
536
- }));
537
- };
538
- /**
539
- * @private
540
- * @return {?}
541
- */
542
- RouterState.prototype.dispatchRouterNavigation = /**
543
- * @private
544
- * @return {?}
545
- */
546
- function () {
547
- /** @type {?} */
548
- var nextRouterState = this._serializer.serialize(this._lastRoutesRecognized.state);
549
- this.dispatchRouterAction(new RouterNavigation(nextRouterState, new RoutesRecognized(this._lastRoutesRecognized.id, this._lastRoutesRecognized.url, this._lastRoutesRecognized.urlAfterRedirects, nextRouterState), this._trigger));
550
- };
551
- /**
552
- * @private
553
- * @param {?} event
554
- * @return {?}
555
- */
556
- RouterState.prototype.dispatchRouterCancel = /**
557
- * @private
558
- * @param {?} event
559
- * @return {?}
560
- */
561
- function (event) {
562
- this.dispatchRouterAction(new RouterCancel((/** @type {?} */ (this._routerState)), this._storeState, event, this._trigger));
563
- };
564
- /**
565
- * @private
566
- * @param {?} event
567
- * @return {?}
568
- */
569
- RouterState.prototype.dispatchRouterError = /**
570
- * @private
571
- * @param {?} event
572
- * @return {?}
573
- */
574
- function (event) {
575
- this.dispatchRouterAction(new RouterError((/** @type {?} */ (this._routerState)), this._storeState, new NavigationError(event.id, event.url, "" + event), this._trigger));
576
- };
577
- /**
578
- * @private
579
- * @template T
580
- * @param {?} action
581
- * @return {?}
582
- */
583
- RouterState.prototype.dispatchRouterAction = /**
584
- * @private
585
- * @template T
586
- * @param {?} action
587
- * @return {?}
588
- */
589
- function (action) {
590
- this._trigger = 'router';
591
- try {
592
- this._store.dispatch(action);
593
- }
594
- finally {
595
- this._trigger = 'none';
596
- }
597
- };
598
- /**
599
- * @private
600
- * @param {?} event
601
- * @return {?}
602
- */
603
- RouterState.prototype.dispatchRouterDataResolved = /**
604
- * @private
605
- * @param {?} event
606
- * @return {?}
607
- */
608
- function (event) {
609
- /** @type {?} */
610
- var routerState = this._serializer.serialize(event.state);
611
- this.dispatchRouterAction(new RouterDataResolved(routerState, event, this._trigger));
612
- };
613
- /**
614
- * @private
615
- * @return {?}
616
- */
617
- RouterState.prototype.reset = /**
618
- * @private
619
- * @return {?}
620
- */
621
- function () {
622
- this._trigger = 'none';
623
- this._storeState = null;
624
- this._routerState = null;
625
- };
626
- var RouterState_1;
627
- RouterState.ctorParameters = function () { return [
628
- { type: Store },
629
- { type: Router },
630
- { type: RouterStateSerializer },
631
- { type: NgZone }
632
- ]; };
633
- RouterState.decorators = [
634
- { type: Injectable }
635
- ];
636
- /** @nocollapse */
637
- RouterState.ctorParameters = function () { return [
638
- { type: Store },
639
- { type: Router },
640
- { type: RouterStateSerializer },
641
- { type: NgZone }
642
- ]; };
643
- __decorate([
644
- Action(Navigate),
645
- __metadata("design:type", Function),
646
- __metadata("design:paramtypes", [Object, Navigate]),
647
- __metadata("design:returntype", void 0)
648
- ], RouterState.prototype, "navigate", null);
649
- __decorate([
650
- Action([RouterNavigation, RouterError, RouterCancel, RouterDataResolved]),
651
- __metadata("design:type", Function),
652
- __metadata("design:paramtypes", [Object, Object]),
653
- __metadata("design:returntype", void 0)
654
- ], RouterState.prototype, "angularRouterAction", null);
655
- __decorate([
656
- Selector(),
657
- __metadata("design:type", Function),
658
- __metadata("design:paramtypes", [Object]),
659
- __metadata("design:returntype", void 0)
660
- ], RouterState, "state", null);
661
- __decorate([
662
- Selector(),
663
- __metadata("design:type", Function),
664
- __metadata("design:paramtypes", [Object]),
665
- __metadata("design:returntype", Object)
666
- ], RouterState, "url", null);
667
- RouterState = RouterState_1 = __decorate([
668
- State({
669
- name: 'router',
670
- defaults: {
671
- state: undefined,
672
- navigationId: undefined,
673
- trigger: 'none'
674
- }
675
- }),
676
- __metadata("design:paramtypes", [Store,
677
- Router,
678
- RouterStateSerializer,
679
- NgZone])
680
- ], RouterState);
681
- return RouterState;
682
- }());
683
- if (false) {
684
- /**
685
- * Determines how navigation was performed by the `RouterState` itself
686
- * or outside via `new Navigate(...)`
687
- * @type {?}
688
- * @private
689
- */
690
- RouterState.prototype._trigger;
691
- /**
692
- * That's the serialized state from the `Router` class
693
- * @type {?}
694
- * @private
695
- */
696
- RouterState.prototype._routerState;
697
- /**
698
- * That's the value of the `RouterState` state
699
- * @type {?}
700
- * @private
701
- */
702
- RouterState.prototype._storeState;
703
- /**
704
- * @type {?}
705
- * @private
706
- */
707
- RouterState.prototype._lastRoutesRecognized;
708
- /**
709
- * @type {?}
710
- * @private
711
- */
712
- RouterState.prototype._subscription;
713
- /**
714
- * @type {?}
715
- * @private
716
- */
717
- RouterState.prototype._store;
718
- /**
719
- * @type {?}
720
- * @private
721
- */
722
- RouterState.prototype._router;
723
- /**
724
- * @type {?}
725
- * @private
726
- */
727
- RouterState.prototype._serializer;
728
- /**
729
- * @type {?}
730
- * @private
731
- */
732
- RouterState.prototype._ngZone;
733
- }
734
-
735
- /**
736
- * @fileoverview added by tsickle
737
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
738
- */
739
- var NgxsRouterPluginModule = /** @class */ (function () {
740
- function NgxsRouterPluginModule() {
741
- }
742
- /**
743
- * @return {?}
744
- */
745
- NgxsRouterPluginModule.forRoot = /**
746
- * @return {?}
747
- */
748
- function () {
749
- return {
750
- ngModule: NgxsRouterPluginModule,
751
- providers: [{ provide: RouterStateSerializer, useClass: DefaultRouterStateSerializer }]
752
- };
753
- };
754
- NgxsRouterPluginModule.decorators = [
755
- { type: NgModule, args: [{
756
- imports: [NgxsModule.forFeature([RouterState])]
757
- },] }
758
- ];
759
- return NgxsRouterPluginModule;
760
- }());
761
-
762
- /**
763
- * @fileoverview added by tsickle
764
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
765
- */
766
-
767
- /**
768
- * @fileoverview added by tsickle
769
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
770
- */
771
-
772
- /**
773
- * @fileoverview added by tsickle
774
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
775
- */
776
-
777
- export { DefaultRouterStateSerializer, Navigate, NgxsRouterPluginModule, RouterCancel, RouterDataResolved, RouterError, RouterNavigation, RouterState, RouterStateSerializer };
778
- //# sourceMappingURL=ngxs-router-plugin.js.map