@@ -4,6 +4,7 @@ import Glob from "./glob";
4
4
import StateQueueManager from "./stateQueueManager" ;
5
5
import StateBuilder from "./stateBuilder" ;
6
6
import StateMatcher from "./stateMatcher" ;
7
+ import StateHandler from "./stateHandler" ;
7
8
import Queue from "../common/queue" ;
8
9
import { Transition } from "../transition/transition"
9
10
import { TransitionRejection , RejectType , RejectFactory } from "../transition/rejectFactory" ;
@@ -622,70 +623,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactoryProvider) {
622
623
current : transQueue . peek . bind ( transQueue )
623
624
} )
624
625
) ) ;
625
-
626
- var stateHandler = {
627
-
628
- runTransition : function runTransition ( transition ) {
629
- // When the transition promise (prepromise; before callbacks) is resolved/rejected, update the $state service
630
- function handleSuccess ( ) { return stateHandler . transitionSuccess ( transition ) ; }
631
- function handleFailure ( error ) { return stateHandler . transitionFailure ( error ) ; }
632
- transition . run ( ) ;
633
- return transition . prepromise . then ( handleSuccess , handleFailure ) ;
634
- } ,
635
-
636
- transitionSuccess : function transitionSuccess ( transition ) {
637
- // TODO: sync on entering/exiting state, not transition success?
638
- transition . views ( "exiting" ) . forEach ( $view . reset . bind ( $view ) ) ;
639
- $view . sync ( ) ;
640
- transition . views ( "entering" ) . forEach ( $view . registerStateViewConfig . bind ( $view ) ) ;
641
- $view . sync ( ) ;
642
-
643
- // Update globals in $state
644
- $state . $current = transition . $to ( ) . $state ( ) ;
645
- $state . current = transition . $to ( ) . state ( ) ;
646
-
647
- stateHandler . updateStateParams ( transition ) ;
648
- transQueue . clear ( ) ;
649
- return transition ;
650
- } ,
651
-
652
- transitionFailure : function transitionFailure ( error ) {
653
- // Handle redirect and abort
654
- if ( error instanceof TransitionRejection ) {
655
- if ( error . type === RejectType . IGNORED ) {
656
- // Update $stateParmas/$state.params/$location.url if transition ignored, but dynamic params have changed.
657
- if ( ! $state . $current . params . $$filter ( not ( not ( prop ( 'dynamic' ) ) ) ) . $$equals ( $stateParams , transition . params ( ) ) ) {
658
- stateHandler . updateStateParams ( transition ) ;
659
- }
660
- return $state . current ;
661
- }
662
-
663
- if ( error . type === RejectType . SUPERSEDED ) {
664
- //if (error.redirected && error.detail instanceof Transition) { // TODO: expose Transition class for instanceof
665
- if ( error . redirected && error . detail instanceof Transition ) {
666
- transQueue . enqueue ( error . detail ) ;
667
- return stateHandler . runTransition ( error . detail ) ;
668
- }
669
- }
670
- }
671
-
672
- return $q . reject ( error ) ;
673
- } ,
674
-
675
- updateStateParams : function updateStateParams ( transition ) {
676
- var options = transition . options ( ) ;
677
- $state . params = transition . params ( ) ;
678
- copy ( $state . params , $stateParams ) ;
679
- $stateParams . $sync ( ) . $off ( ) ;
680
-
681
- if ( options . location && $state . $current . navigable ) {
682
- $urlRouter . push ( $state . $current . navigable . url , $stateParams , { replace : options . location === 'replace' } ) ;
683
- }
684
-
685
- $urlRouter . update ( true ) ;
686
- }
687
- } ;
688
-
626
+ let stateHandler = new StateHandler ( $urlRouter , $view , $state , $stateParams , $q , transQueue ) ;
689
627
var result = stateHandler . runTransition ( transition ) ;
690
628
result . finally ( ( ) => transQueue . remove ( transition ) ) ;
691
629
@@ -1013,4 +951,4 @@ function $StateParamsProvider() {
1013
951
angular . module ( 'ui.router.state' )
1014
952
. provider ( '$stateParams' , < IServiceProviderFactory > $StateParamsProvider )
1015
953
. provider ( '$state' , < IServiceProviderFactory > $StateProvider )
1016
- . run ( [ '$state' , function ( $state ) { /* This effectively calls $get() to init when we enter runtime */ } ] ) ;
954
+ . run ( [ '$state' , function ( $state ) { /* This effectively calls $get() to init when we enter runtime */ } ] ) ;
0 commit comments