@ngxs/router-plugin 3.7.6-dev.master-95e4742 → 3.7.6-dev.master-2df2f65

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.
@@ -266,7 +266,7 @@
266
266
  *
267
267
  */
268
268
  /**
269
- * An action dispatched when the router navigates.
269
+ * An action dispatched when the router starts the navigation.
270
270
  * @template T
271
271
  */
272
272
  var /**
@@ -275,6 +275,42 @@
275
275
  *
276
276
  */
277
277
  /**
278
+ * An action dispatched when the router starts the navigation.
279
+ * @template T
280
+ */
281
+ RouterRequest = /** @class */ (function () {
282
+ function RouterRequest(routerState, event, trigger) {
283
+ if (trigger === void 0) { trigger = 'none'; }
284
+ this.routerState = routerState;
285
+ this.event = event;
286
+ this.trigger = trigger;
287
+ }
288
+ Object.defineProperty(RouterRequest, "type", {
289
+ get: /**
290
+ * @return {?}
291
+ */
292
+ function () {
293
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
294
+ return '[Router] RouterRequest';
295
+ },
296
+ enumerable: true,
297
+ configurable: true
298
+ });
299
+ return RouterRequest;
300
+ }());
301
+ if (false) {
302
+ /** @type {?} */
303
+ RouterRequest.prototype.routerState;
304
+ /** @type {?} */
305
+ RouterRequest.prototype.event;
306
+ /** @type {?} */
307
+ RouterRequest.prototype.trigger;
308
+ }
309
+ /**
310
+ * An action dispatched when the router navigates.
311
+ * @template T
312
+ */
313
+ var /**
278
314
  * An action dispatched when the router navigates.
279
315
  * @template T
280
316
  */
@@ -420,6 +456,42 @@
420
456
  /** @type {?} */
421
457
  RouterDataResolved.prototype.trigger;
422
458
  }
459
+ /**
460
+ * An action dispatched when the router navigation has been finished successfully.
461
+ * @template T
462
+ */
463
+ var /**
464
+ * An action dispatched when the router navigation has been finished successfully.
465
+ * @template T
466
+ */
467
+ RouterNavigated = /** @class */ (function () {
468
+ function RouterNavigated(routerState, event, trigger) {
469
+ if (trigger === void 0) { trigger = 'none'; }
470
+ this.routerState = routerState;
471
+ this.event = event;
472
+ this.trigger = trigger;
473
+ }
474
+ Object.defineProperty(RouterNavigated, "type", {
475
+ get: /**
476
+ * @return {?}
477
+ */
478
+ function () {
479
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
480
+ return '[Router] RouterNavigated';
481
+ },
482
+ enumerable: true,
483
+ configurable: true
484
+ });
485
+ return RouterNavigated;
486
+ }());
487
+ if (false) {
488
+ /** @type {?} */
489
+ RouterNavigated.prototype.routerState;
490
+ /** @type {?} */
491
+ RouterNavigated.prototype.event;
492
+ /** @type {?} */
493
+ RouterNavigated.prototype.trigger;
494
+ }
423
495
 
424
496
  /**
425
497
  * @fileoverview added by tsickle
@@ -513,6 +585,43 @@
513
585
  return DefaultRouterStateSerializer;
514
586
  }());
515
587
 
588
+ /**
589
+ * @fileoverview added by tsickle
590
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
591
+ */
592
+ /** @enum {number} */
593
+ var NavigationActionTiming = {
594
+ PreActivation: 1,
595
+ PostActivation: 2,
596
+ };
597
+ /**
598
+ * @record
599
+ */
600
+ function NgxsRouterPluginOptions() { }
601
+ if (false) {
602
+ /** @type {?|undefined} */
603
+ NgxsRouterPluginOptions.prototype.navigationActionTiming;
604
+ }
605
+ /** @type {?} */
606
+ var USER_OPTIONS = new core.InjectionToken('USER_OPTIONS', { providedIn: 'root', factory: (/**
607
+ * @return {?}
608
+ */
609
+ function () { return undefined; }) });
610
+ /** @type {?} */
611
+ var NGXS_ROUTER_PLUGIN_OPTIONS = new core.InjectionToken('NGXS_ROUTER_PLUGIN_OPTIONS', { providedIn: 'root', factory: (/**
612
+ * @return {?}
613
+ */
614
+ function () { return ({}); }) });
615
+ /**
616
+ * @param {?} options
617
+ * @return {?}
618
+ */
619
+ function createRouterPluginOptions(options) {
620
+ return {
621
+ navigationActionTiming: (options && options.navigationActionTiming) || 1 /* PreActivation */
622
+ };
623
+ }
624
+
516
625
  /**
517
626
  * @fileoverview added by tsickle
518
627
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -531,7 +640,7 @@
531
640
  RouterStateModel.prototype.trigger;
532
641
  }
533
642
  var RouterState = /** @class */ (function () {
534
- function RouterState(_store, _router, _serializer, _ngZone) {
643
+ function RouterState(_store, _router, _serializer, _ngZone, injector) {
535
644
  this._store = _store;
536
645
  this._router = _router;
537
646
  this._serializer = _serializer;
@@ -549,10 +658,14 @@
549
658
  * That's the value of the `RouterState` state
550
659
  */
551
660
  this._storeState = null;
552
- this._lastRoutesRecognized = (/** @type {?} */ (null));
661
+ this._lastEvent = null;
553
662
  this._subscription = new rxjs.Subscription();
554
- this.setUpStoreListener();
555
- this.setUpRouterEventsListener();
663
+ this._options = null;
664
+ // Note: do not use `@Inject` since it fails on lower versions of Angular with Jest
665
+ // integration, it cannot resolve the token provider.
666
+ this._options = injector.get(NGXS_ROUTER_PLUGIN_OPTIONS, null);
667
+ this._setUpStoreListener();
668
+ this._setUpRouterEventsListener();
556
669
  }
557
670
  RouterState_1 = RouterState;
558
671
  /**
@@ -618,13 +731,17 @@
618
731
  * @return {?}
619
732
  */
620
733
  function (ctx, action) {
621
- ctx.setState(__assign({}, ctx.getState(), { trigger: action.trigger, state: action.routerState, navigationId: action.event.id }));
734
+ ctx.setState({
735
+ trigger: action.trigger,
736
+ state: action.routerState,
737
+ navigationId: action.event.id
738
+ });
622
739
  };
623
740
  /**
624
741
  * @private
625
742
  * @return {?}
626
743
  */
627
- RouterState.prototype.setUpStoreListener = /**
744
+ RouterState.prototype._setUpStoreListener = /**
628
745
  * @private
629
746
  * @return {?}
630
747
  */
@@ -638,160 +755,201 @@
638
755
  * @return {?}
639
756
  */
640
757
  function (state) {
641
- _this.navigateIfNeeded(state);
758
+ _this._navigateIfNeeded(state);
642
759
  }));
643
760
  this._subscription.add(subscription);
644
761
  };
762
+ /**
763
+ * @private
764
+ * @param {?} routerState
765
+ * @return {?}
766
+ */
767
+ RouterState.prototype._navigateIfNeeded = /**
768
+ * @private
769
+ * @param {?} routerState
770
+ * @return {?}
771
+ */
772
+ function (routerState) {
773
+ var _this = this;
774
+ if (routerState && routerState.trigger === 'devtools') {
775
+ this._storeState = this._store.selectSnapshot(RouterState_1);
776
+ }
777
+ /** @type {?} */
778
+ var canSkipNavigation = !this._storeState ||
779
+ !this._storeState.state ||
780
+ !routerState ||
781
+ routerState.trigger === 'router' ||
782
+ this._router.url === this._storeState.state.url ||
783
+ this._lastEvent instanceof router.NavigationStart;
784
+ if (canSkipNavigation) {
785
+ return;
786
+ }
787
+ this._storeState = this._store.selectSnapshot(RouterState_1);
788
+ this._trigger = 'store';
789
+ this._ngZone.run((/**
790
+ * @return {?}
791
+ */
792
+ function () { return _this._router.navigateByUrl((/** @type {?} */ ((/** @type {?} */ (_this._storeState)).state)).url); }));
793
+ };
645
794
  /**
646
795
  * @private
647
796
  * @return {?}
648
797
  */
649
- RouterState.prototype.setUpRouterEventsListener = /**
798
+ RouterState.prototype._setUpRouterEventsListener = /**
650
799
  * @private
651
800
  * @return {?}
652
801
  */
653
802
  function () {
654
803
  var _this = this;
655
804
  /** @type {?} */
805
+ var dispatchRouterNavigationLate = this._options != null &&
806
+ this._options.navigationActionTiming === 2 /* PostActivation */;
807
+ /** @type {?} */
808
+ var lastRoutesRecognized;
809
+ /** @type {?} */
656
810
  var subscription = this._router.events.subscribe((/**
657
811
  * @param {?} event
658
812
  * @return {?}
659
813
  */
660
814
  function (event) {
815
+ _this._lastEvent = event;
661
816
  if (event instanceof router.NavigationStart) {
662
- _this.navigationStart();
817
+ _this._navigationStart(event);
663
818
  }
664
819
  else if (event instanceof router.RoutesRecognized) {
665
- _this._lastRoutesRecognized = event;
820
+ lastRoutesRecognized = event;
821
+ if (!dispatchRouterNavigationLate && _this._trigger !== 'store') {
822
+ _this._dispatchRouterNavigation(lastRoutesRecognized);
823
+ }
666
824
  }
667
825
  else if (event instanceof router.ResolveEnd) {
668
- _this.dispatchRouterDataResolved(event);
826
+ _this._dispatchRouterDataResolved(event);
669
827
  }
670
828
  else if (event instanceof router.NavigationCancel) {
671
- _this.dispatchRouterCancel(event);
672
- _this.reset();
829
+ _this._dispatchRouterCancel(event);
830
+ _this._reset();
673
831
  }
674
832
  else if (event instanceof router.NavigationError) {
675
- _this.dispatchRouterError(event);
676
- _this.reset();
833
+ _this._dispatchRouterError(event);
834
+ _this._reset();
677
835
  }
678
836
  else if (event instanceof router.NavigationEnd) {
679
- _this.navigationEnd();
680
- _this.reset();
837
+ if (_this._trigger !== 'store') {
838
+ if (dispatchRouterNavigationLate) {
839
+ _this._dispatchRouterNavigation(lastRoutesRecognized);
840
+ }
841
+ _this._dispatchRouterNavigated(event);
842
+ }
843
+ _this._reset();
681
844
  }
682
845
  }));
683
846
  this._subscription.add(subscription);
684
847
  };
848
+ /** Reacts to `NavigationStart`. */
685
849
  /**
850
+ * Reacts to `NavigationStart`.
686
851
  * @private
852
+ * @param {?} event
687
853
  * @return {?}
688
854
  */
689
- RouterState.prototype.navigationStart = /**
855
+ RouterState.prototype._navigationStart = /**
856
+ * Reacts to `NavigationStart`.
690
857
  * @private
858
+ * @param {?} event
691
859
  * @return {?}
692
860
  */
693
- function () {
861
+ function (event) {
694
862
  this._routerState = this._serializer.serialize(this._router.routerState.snapshot);
695
863
  if (this._trigger !== 'none') {
696
864
  this._storeState = this._store.selectSnapshot(RouterState_1);
865
+ this._dispatchRouterAction(new RouterRequest(this._routerState, event, this._trigger));
697
866
  }
698
867
  };
868
+ /** Reacts to `ResolveEnd`. */
699
869
  /**
870
+ * Reacts to `ResolveEnd`.
700
871
  * @private
872
+ * @param {?} event
701
873
  * @return {?}
702
874
  */
703
- RouterState.prototype.navigationEnd = /**
704
- * @private
705
- * @return {?}
706
- */
707
- function () {
708
- if (this.shouldDispatchRouterNavigation()) {
709
- this.dispatchRouterNavigation();
710
- }
711
- };
712
- /**
713
- * @private
714
- * @return {?}
715
- */
716
- RouterState.prototype.shouldDispatchRouterNavigation = /**
875
+ RouterState.prototype._dispatchRouterDataResolved = /**
876
+ * Reacts to `ResolveEnd`.
717
877
  * @private
878
+ * @param {?} event
718
879
  * @return {?}
719
880
  */
720
- function () {
721
- if (!this._storeState)
722
- return true;
723
- return this._trigger !== 'store';
881
+ function (event) {
882
+ /** @type {?} */
883
+ var routerState = this._serializer.serialize(event.state);
884
+ this._dispatchRouterAction(new RouterDataResolved(routerState, event, this._trigger));
724
885
  };
886
+ /** Reacts to `RoutesRecognized` or `NavigationEnd`, depends on the `navigationActionTiming`. */
725
887
  /**
888
+ * Reacts to `RoutesRecognized` or `NavigationEnd`, depends on the `navigationActionTiming`.
726
889
  * @private
727
- * @param {?} state
890
+ * @param {?} lastRoutesRecognized
728
891
  * @return {?}
729
892
  */
730
- RouterState.prototype.navigateIfNeeded = /**
893
+ RouterState.prototype._dispatchRouterNavigation = /**
894
+ * Reacts to `RoutesRecognized` or `NavigationEnd`, depends on the `navigationActionTiming`.
731
895
  * @private
732
- * @param {?} state
896
+ * @param {?} lastRoutesRecognized
733
897
  * @return {?}
734
898
  */
735
- function (state) {
736
- var _this = this;
737
- if (state && state.trigger === 'devtools') {
738
- this._storeState = this._store.selectSnapshot(RouterState_1);
739
- }
899
+ function (lastRoutesRecognized) {
740
900
  /** @type {?} */
741
- var canSkipNavigation = !this._storeState ||
742
- !this._storeState.state ||
743
- !state ||
744
- state.trigger === 'router' ||
745
- this._router.url === this._storeState.state.url;
746
- if (canSkipNavigation) {
747
- return;
748
- }
749
- this._trigger = 'store';
750
- this._ngZone.run((/**
751
- * @return {?}
752
- */
753
- function () {
754
- _this._router.navigateByUrl((/** @type {?} */ ((/** @type {?} */ (_this._storeState)).state)).url);
755
- }));
901
+ var nextRouterState = this._serializer.serialize(lastRoutesRecognized.state);
902
+ this._dispatchRouterAction(new RouterNavigation(nextRouterState, new router.RoutesRecognized(lastRoutesRecognized.id, lastRoutesRecognized.url, lastRoutesRecognized.urlAfterRedirects, nextRouterState), this._trigger));
756
903
  };
904
+ /** Reacts to `NavigationCancel`. */
757
905
  /**
906
+ * Reacts to `NavigationCancel`.
758
907
  * @private
908
+ * @param {?} event
759
909
  * @return {?}
760
910
  */
761
- RouterState.prototype.dispatchRouterNavigation = /**
911
+ RouterState.prototype._dispatchRouterCancel = /**
912
+ * Reacts to `NavigationCancel`.
762
913
  * @private
914
+ * @param {?} event
763
915
  * @return {?}
764
916
  */
765
- function () {
766
- /** @type {?} */
767
- var nextRouterState = this._serializer.serialize(this._lastRoutesRecognized.state);
768
- this.dispatchRouterAction(new RouterNavigation(nextRouterState, new router.RoutesRecognized(this._lastRoutesRecognized.id, this._lastRoutesRecognized.url, this._lastRoutesRecognized.urlAfterRedirects, nextRouterState), this._trigger));
917
+ function (event) {
918
+ this._dispatchRouterAction(new RouterCancel((/** @type {?} */ (this._routerState)), this._storeState, event, this._trigger));
769
919
  };
920
+ /** Reacts to `NavigationEnd`. */
770
921
  /**
922
+ * Reacts to `NavigationEnd`.
771
923
  * @private
772
924
  * @param {?} event
773
925
  * @return {?}
774
926
  */
775
- RouterState.prototype.dispatchRouterCancel = /**
927
+ RouterState.prototype._dispatchRouterError = /**
928
+ * Reacts to `NavigationEnd`.
776
929
  * @private
777
930
  * @param {?} event
778
931
  * @return {?}
779
932
  */
780
933
  function (event) {
781
- this.dispatchRouterAction(new RouterCancel((/** @type {?} */ (this._routerState)), this._storeState, event, this._trigger));
934
+ this._dispatchRouterAction(new RouterError((/** @type {?} */ (this._routerState)), this._storeState, new router.NavigationError(event.id, event.url, "" + event), this._trigger));
782
935
  };
936
+ /** Reacts to `NavigationEnd`. */
783
937
  /**
938
+ * Reacts to `NavigationEnd`.
784
939
  * @private
785
940
  * @param {?} event
786
941
  * @return {?}
787
942
  */
788
- RouterState.prototype.dispatchRouterError = /**
943
+ RouterState.prototype._dispatchRouterNavigated = /**
944
+ * Reacts to `NavigationEnd`.
789
945
  * @private
790
946
  * @param {?} event
791
947
  * @return {?}
792
948
  */
793
949
  function (event) {
794
- this.dispatchRouterAction(new RouterError((/** @type {?} */ (this._routerState)), this._storeState, new router.NavigationError(event.id, event.url, "" + event), this._trigger));
950
+ /** @type {?} */
951
+ var routerState = this._serializer.serialize(this._router.routerState.snapshot);
952
+ this._dispatchRouterAction(new RouterNavigated(routerState, event, this._trigger));
795
953
  };
796
954
  /**
797
955
  * @private
@@ -799,7 +957,7 @@
799
957
  * @param {?} action
800
958
  * @return {?}
801
959
  */
802
- RouterState.prototype.dispatchRouterAction = /**
960
+ RouterState.prototype._dispatchRouterAction = /**
803
961
  * @private
804
962
  * @template T
805
963
  * @param {?} action
@@ -814,26 +972,11 @@
814
972
  this._trigger = 'none';
815
973
  }
816
974
  };
817
- /**
818
- * @private
819
- * @param {?} event
820
- * @return {?}
821
- */
822
- RouterState.prototype.dispatchRouterDataResolved = /**
823
- * @private
824
- * @param {?} event
825
- * @return {?}
826
- */
827
- function (event) {
828
- /** @type {?} */
829
- var routerState = this._serializer.serialize(event.state);
830
- this.dispatchRouterAction(new RouterDataResolved(routerState, event, this._trigger));
831
- };
832
975
  /**
833
976
  * @private
834
977
  * @return {?}
835
978
  */
836
- RouterState.prototype.reset = /**
979
+ RouterState.prototype._reset = /**
837
980
  * @private
838
981
  * @return {?}
839
982
  */
@@ -847,7 +990,8 @@
847
990
  { type: store.Store },
848
991
  { type: router.Router },
849
992
  { type: RouterStateSerializer },
850
- { type: core.NgZone }
993
+ { type: core.NgZone },
994
+ { type: core.Injector }
851
995
  ]; };
852
996
  RouterState.decorators = [
853
997
  { type: core.Injectable }
@@ -857,7 +1001,8 @@
857
1001
  { type: store.Store },
858
1002
  { type: router.Router },
859
1003
  { type: RouterStateSerializer },
860
- { type: core.NgZone }
1004
+ { type: core.NgZone },
1005
+ { type: core.Injector }
861
1006
  ]; };
862
1007
  __decorate([
863
1008
  store.Action(Navigate),
@@ -866,7 +1011,14 @@
866
1011
  __metadata("design:returntype", void 0)
867
1012
  ], RouterState.prototype, "navigate", null);
868
1013
  __decorate([
869
- store.Action([RouterNavigation, RouterError, RouterCancel, RouterDataResolved]),
1014
+ store.Action([
1015
+ RouterRequest,
1016
+ RouterNavigation,
1017
+ RouterError,
1018
+ RouterCancel,
1019
+ RouterDataResolved,
1020
+ RouterNavigated
1021
+ ]),
870
1022
  __metadata("design:type", Function),
871
1023
  __metadata("design:paramtypes", [Object, Object]),
872
1024
  __metadata("design:returntype", void 0)
@@ -895,7 +1047,8 @@
895
1047
  __metadata("design:paramtypes", [store.Store,
896
1048
  router.Router,
897
1049
  RouterStateSerializer,
898
- core.NgZone])
1050
+ core.NgZone,
1051
+ core.Injector])
899
1052
  ], RouterState);
900
1053
  return RouterState;
901
1054
  }());
@@ -923,12 +1076,17 @@
923
1076
  * @type {?}
924
1077
  * @private
925
1078
  */
926
- RouterState.prototype._lastRoutesRecognized;
1079
+ RouterState.prototype._lastEvent;
927
1080
  /**
928
1081
  * @type {?}
929
1082
  * @private
930
1083
  */
931
1084
  RouterState.prototype._subscription;
1085
+ /**
1086
+ * @type {?}
1087
+ * @private
1088
+ */
1089
+ RouterState.prototype._options;
932
1090
  /**
933
1091
  * @type {?}
934
1092
  * @private
@@ -959,15 +1117,25 @@
959
1117
  function NgxsRouterPluginModule() {
960
1118
  }
961
1119
  /**
1120
+ * @param {?=} options
962
1121
  * @return {?}
963
1122
  */
964
1123
  NgxsRouterPluginModule.forRoot = /**
1124
+ * @param {?=} options
965
1125
  * @return {?}
966
1126
  */
967
- function () {
1127
+ function (options) {
968
1128
  return {
969
1129
  ngModule: NgxsRouterPluginModule,
970
- providers: [{ provide: RouterStateSerializer, useClass: DefaultRouterStateSerializer }]
1130
+ providers: [
1131
+ { provide: USER_OPTIONS, useValue: options },
1132
+ {
1133
+ provide: NGXS_ROUTER_PLUGIN_OPTIONS,
1134
+ useFactory: createRouterPluginOptions,
1135
+ deps: [USER_OPTIONS]
1136
+ },
1137
+ { provide: RouterStateSerializer, useClass: DefaultRouterStateSerializer }
1138
+ ]
971
1139
  };
972
1140
  };
973
1141
  NgxsRouterPluginModule.decorators = [
@@ -984,9 +1152,14 @@
984
1152
  exports.RouterCancel = RouterCancel;
985
1153
  exports.RouterDataResolved = RouterDataResolved;
986
1154
  exports.RouterError = RouterError;
1155
+ exports.RouterNavigated = RouterNavigated;
987
1156
  exports.RouterNavigation = RouterNavigation;
1157
+ exports.RouterRequest = RouterRequest;
988
1158
  exports.RouterState = RouterState;
989
1159
  exports.RouterStateSerializer = RouterStateSerializer;
1160
+ exports.ɵb = USER_OPTIONS;
1161
+ exports.ɵc = NGXS_ROUTER_PLUGIN_OPTIONS;
1162
+ exports.ɵd = createRouterPluginOptions;
990
1163
 
991
1164
  Object.defineProperty(exports, '__esModule', { value: true });
992
1165