@@ -6,27 +6,18 @@ import {
66import { Queue } from "../common/queue" ;
77import { IServiceProviderFactory , IPromise } from "angular" ;
88
9- import { StateService , StateDeclaration , StateOrName , HrefOptions , ViewDeclaration } from "./interface" ;
10- import { Glob } from "./glob" ;
11- import { StateQueueManager } from "./stateQueueManager" ;
12- import { StateBuilder } from "./stateBuilder" ;
13- import { StateMatcher } from "./stateMatcher" ;
14- import { TargetState } from "./targetState" ;
9+ import { StateService , StateDeclaration , StateOrName , HrefOptions , ViewDeclaration } from "./interface" ;
10+ import { Glob , StateQueueManager , StateBuilder , StateMatcher , TargetState } from "./module" ;
1511
1612import { ITransitionService , TransitionOptions , TreeChanges } from "../transition/interface" ;
17- import { Transition } from "../transition/transition" ;
18- import { RejectFactory } from "../transition/rejectFactory" ;
19- import { defaultTransOpts } from "../transition/transitionService" ;
13+ import { Transition , RejectFactory , defaultTransOpts } from "../transition/module" ;
2014
21- import { Node } from "../path/node" ;
22- import { PathFactory } from "../path/pathFactory" ;
15+ import { PathFactory , Node } from "../path/module" ;
2316
2417import { RawParams , ParamsOrArray } from "../params/interface" ;
2518import { TransitionManager } from "./hooks/transitionManager" ;
2619
27- import { paramTypes } from "../params/paramTypes" ;
28- import { Param } from "../params/param" ;
29- import { Type } from "../params/type" ;
20+ import { paramTypes , Param , Type , StateParams } from "../params/module" ;
3021
3122import { UrlMatcher } from "../url/urlMatcher" ;
3223import { ViewConfig } from "../view/view" ;
@@ -913,142 +904,6 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactoryProvider) {
913904 }
914905}
915906
916- export function StateParams ( ) { }
917-
918- $StateParamsProvider . $inject = [ ] ;
919- function $StateParamsProvider ( ) {
920-
921- function stateParamsFactory ( ) {
922- let observers = { } , current = { } ;
923-
924- function unhook ( key , func ) {
925- return function ( ) {
926- forEach ( key . split ( " " ) , function ( k ) {
927- observers [ k ] . splice ( observers [ k ] . indexOf ( func ) , 1 ) ;
928- } ) ;
929- } ;
930- }
931-
932- function observeChange ( key , val ?: any ) {
933- if ( ! observers [ key ] || ! observers [ key ] . length ) return ;
934-
935- forEach ( observers [ key ] , function ( func ) {
936- func ( val ) ;
937- } ) ;
938- }
939-
940-
941- StateParams . prototype . $digest = function ( ) {
942- function updateValue ( val , key ) {
943- if ( val === current [ key ] || ! this . hasOwnProperty ( key ) ) return ;
944- current [ key ] = val ;
945- observeChange ( key , val ) ;
946- }
947- forEach ( this , updateValue , this ) ;
948- } ;
949-
950- /**
951- * Merges a set of parameters with all parameters inherited between the common parents of the
952- * current state and a given destination state.
953- *
954- * @param {Object } newParams The set of parameters which will be composited with inherited params.
955- * @param {Object } $current Internal definition of object representing the current state.
956- * @param {Object } $to Internal definition of object representing state to transition to.
957- */
958- StateParams . prototype . $inherit = function ( newParams , $current , $to ) {
959- let parents = ancestors ( $current , $to ) , parentParams , inherited = { } , inheritList = [ ] ;
960-
961- for ( let i in parents ) {
962- if ( ! parents [ i ] . params ) continue ;
963- parentParams = Object . keys ( parents [ i ] . params ) ;
964- if ( ! parentParams . length ) continue ;
965-
966- for ( let j in parentParams ) {
967- if ( inheritList . indexOf ( parentParams [ j ] ) >= 0 ) continue ;
968- inheritList . push ( parentParams [ j ] ) ;
969- inherited [ parentParams [ j ] ] = this [ parentParams [ j ] ] ;
970- }
971- }
972- return extend ( { } , inherited , newParams ) ;
973- } ;
974-
975- StateParams . prototype . $set = function ( params , url ) {
976- let hasChanged = false , abort = false ;
977-
978- if ( url ) {
979- forEach ( params , function ( val , key ) {
980- if ( ( url . parameter ( key ) || { } ) . dynamic !== true ) abort = true ;
981- } ) ;
982- }
983- if ( abort ) return false ;
984-
985- function updateValue ( val , key ) {
986- if ( val !== this [ key ] ) {
987- this [ key ] = val ;
988- observeChange ( key ) ;
989- hasChanged = true ;
990- }
991- }
992- forEach ( params , updateValue , this ) ;
993-
994- this . $sync ( ) ;
995- return hasChanged ;
996- } ;
997-
998- StateParams . prototype . $sync = function ( ) {
999- copy ( this , current ) ;
1000- return this ;
1001- } ;
1002-
1003- StateParams . prototype . $off = function ( ) {
1004- observers = { } ;
1005- return this ;
1006- } ;
1007-
1008- StateParams . prototype . $raw = function ( ) {
1009- let raw = { } ;
1010- for ( let key in this ) {
1011- if ( ! StateParams . prototype . hasOwnProperty ( key ) )
1012- raw [ key ] = this [ key ] ;
1013- }
1014- return raw ;
1015- } ;
1016-
1017- StateParams . prototype . $localize = function ( state , params ) {
1018- let localized = new StateParams ( ) ;
1019- params = params || this ;
1020-
1021- forEach ( state . params , function ( val , key ) {
1022- localized [ key ] = params [ key ] ;
1023- } ) ;
1024- return localized ;
1025- } ;
1026-
1027- StateParams . prototype . $observe = function ( key , func ) {
1028- forEach ( key . split ( " " ) , function ( k ) {
1029- ( observers [ k ] || ( observers [ k ] = [ ] ) ) . push ( func ) ;
1030- } ) ;
1031- return unhook ( key , func ) ;
1032- } ;
1033-
1034- return new StateParams ( ) ;
1035- }
1036-
1037- let global = stateParamsFactory ( ) ;
1038-
1039- this . $get = $get ;
1040- $get . $inject = [ '$rootScope' ] ;
1041- function $get ( $rootScope ) {
1042-
1043- $rootScope . $watch ( function ( ) {
1044- global . $digest ( ) ;
1045- } ) ;
1046-
1047- return global ;
1048- }
1049- }
1050-
1051907angular . module ( 'ui.router.state' )
1052- . provider ( '$stateParams' , < IServiceProviderFactory > $StateParamsProvider )
1053908 . provider ( '$state' , < IServiceProviderFactory > $StateProvider )
1054909 . run ( [ '$state' , function ( $state ) { /* This effectively calls $get() to init when we enter runtime */ } ] ) ;
0 commit comments