1
- /** @ng 2api @module directives */
2
- /** */
3
1
import { Directive , Output , EventEmitter , ContentChildren , QueryList , Host , Self , Optional } from '@angular/core' ;
4
2
import { UISref } from './uiSref' ;
5
3
import {
@@ -21,7 +19,7 @@ import {
21
19
import { Subscription , Observable , BehaviorSubject , of , from , combineLatest , concat } from 'rxjs' ;
22
20
import { switchMap , map , tap } from 'rxjs/operators' ;
23
21
24
- /** @internalapi */
22
+ /** @internal */
25
23
interface TransEvt {
26
24
evt : string ;
27
25
trans : Transition ;
@@ -43,7 +41,7 @@ export interface SrefStatus {
43
41
targetStates : TargetState [ ] ;
44
42
}
45
43
46
- /** @internalapi */
44
+ /** @internal */
47
45
const inactiveStatus : SrefStatus = {
48
46
active : false ,
49
47
exact : false ,
@@ -58,15 +56,15 @@ const inactiveStatus: SrefStatus = {
58
56
* The predicate returns true when the target state (and param values)
59
57
* match the (tail of) the path, and the path's param values
60
58
*
61
- * @internalapi
59
+ * @internal
62
60
*/
63
61
const pathMatches = ( target : TargetState ) : Predicate < PathNode [ ] > => {
64
62
if ( ! target . exists ( ) ) return ( ) => false ;
65
63
const state : StateObject = target . $state ( ) ;
66
64
const targetParamVals = target . params ( ) ;
67
65
const targetPath : PathNode [ ] = PathUtils . buildPath ( target ) ;
68
66
const paramSchema : Param [ ] = targetPath
69
- . map ( node => node . paramSchema )
67
+ . map ( ( node ) => node . paramSchema )
70
68
. reduce ( unnestR , [ ] )
71
69
. filter ( ( param : Param ) => targetParamVals . hasOwnProperty ( param . id ) ) ;
72
70
@@ -83,10 +81,10 @@ const pathMatches = (target: TargetState): Predicate<PathNode[]> => {
83
81
* Expands the path to [c], [c, d]
84
82
* Then appends each to [a,b,] and returns: [a, b, c], [a, b, c, d]
85
83
*
86
- * @internalapi
84
+ * @internal
87
85
*/
88
86
function spreadToSubPaths ( basePath : PathNode [ ] , appendPath : PathNode [ ] ) : PathNode [ ] [ ] {
89
- return appendPath . map ( node => basePath . concat ( PathUtils . subPath ( appendPath , n => n . state === node . state ) ) ) ;
87
+ return appendPath . map ( ( node ) => basePath . concat ( PathUtils . subPath ( appendPath , ( n ) => n . state === node . state ) ) ) ;
90
88
}
91
89
92
90
/**
@@ -95,7 +93,7 @@ function spreadToSubPaths(basePath: PathNode[], appendPath: PathNode[]): PathNod
95
93
* which represents the current status of that Sref:
96
94
* active, activeEq (exact match), entering, exiting
97
95
*
98
- * @internalapi
96
+ * @internal
99
97
*/
100
98
function getSrefStatus ( event : TransEvt , srefTarget : TargetState ) : SrefStatus {
101
99
const pathMatchesTarget = pathMatches ( srefTarget ) ;
@@ -105,22 +103,13 @@ function getSrefStatus(event: TransEvt, srefTarget: TargetState): SrefStatus {
105
103
const isSuccessEvent = event . evt === 'success' ;
106
104
const activePath : PathNode [ ] = isSuccessEvent ? tc . to : tc . from ;
107
105
108
- const isActive = ( ) =>
109
- spreadToSubPaths ( [ ] , activePath )
110
- . map ( pathMatchesTarget )
111
- . reduce ( anyTrueR , false ) ;
106
+ const isActive = ( ) => spreadToSubPaths ( [ ] , activePath ) . map ( pathMatchesTarget ) . reduce ( anyTrueR , false ) ;
112
107
113
108
const isExact = ( ) => pathMatchesTarget ( activePath ) ;
114
109
115
- const isEntering = ( ) =>
116
- spreadToSubPaths ( tc . retained , tc . entering )
117
- . map ( pathMatchesTarget )
118
- . reduce ( anyTrueR , false ) ;
110
+ const isEntering = ( ) => spreadToSubPaths ( tc . retained , tc . entering ) . map ( pathMatchesTarget ) . reduce ( anyTrueR , false ) ;
119
111
120
- const isExiting = ( ) =>
121
- spreadToSubPaths ( tc . retained , tc . exiting )
122
- . map ( pathMatchesTarget )
123
- . reduce ( anyTrueR , false ) ;
112
+ const isExiting = ( ) => spreadToSubPaths ( tc . retained , tc . exiting ) . map ( pathMatchesTarget ) . reduce ( anyTrueR , false ) ;
124
113
125
114
return {
126
115
active : isActive ( ) ,
@@ -131,7 +120,7 @@ function getSrefStatus(event: TransEvt, srefTarget: TargetState): SrefStatus {
131
120
} as SrefStatus ;
132
121
}
133
122
134
- /** @internalapi */
123
+ /** @internal */
135
124
function mergeSrefStatus ( left : SrefStatus , right : SrefStatus ) : SrefStatus {
136
125
return {
137
126
active : left . active || right . active ,
@@ -204,11 +193,11 @@ export class UISrefStatus {
204
193
/** The current status */
205
194
status : SrefStatus ;
206
195
207
- /** @internalapi */ private _subscription : Subscription ;
208
- /** @internalapi */ private _srefChangesSub : Subscription ;
209
- /** @internalapi */ private _srefs$ : BehaviorSubject < UISref [ ] > ;
210
- /** @internalapi */ private _globals : UIRouterGlobals ;
211
- /** @internalapi */ private _hostUiSref : UISref ;
196
+ /** @internal */ private _subscription : Subscription ;
197
+ /** @internal */ private _srefChangesSub : Subscription ;
198
+ /** @internal */ private _srefs$ : BehaviorSubject < UISref [ ] > ;
199
+ /** @internal */ private _globals : UIRouterGlobals ;
200
+ /** @internal */ private _hostUiSref : UISref ;
212
201
constructor ( @Host ( ) @Self ( ) @Optional ( ) _hostUiSref : UISref , _globals : UIRouterGlobals ) {
213
202
this . _globals = _globals ;
214
203
this . _hostUiSref = _hostUiSref ;
@@ -223,25 +212,25 @@ export class UISrefStatus {
223
212
const event = ( evt : string ) => ( { evt, trans } as TransEvt ) ;
224
213
225
214
const transStart$ = of ( event ( 'start' ) ) ;
226
- const transResult = trans . promise . then ( ( ) => event ( 'success' ) , ( ) => event ( 'error' ) ) ;
215
+ const transResult = trans . promise . then (
216
+ ( ) => event ( 'success' ) ,
217
+ ( ) => event ( 'error' )
218
+ ) ;
227
219
const transFinish$ = from ( transResult ) ;
228
220
229
221
return concat ( transStart$ , transFinish$ ) ;
230
222
} )
231
223
) ;
232
224
233
225
const withHostSref = ( childrenSrefs : UISref [ ] ) =>
234
- childrenSrefs
235
- . concat ( this . _hostUiSref )
236
- . filter ( identity )
237
- . reduce ( uniqR , [ ] ) ;
226
+ childrenSrefs . concat ( this . _hostUiSref ) . filter ( identity ) . reduce ( uniqR , [ ] ) ;
238
227
239
228
// Watch the @ContentChildren UISref[] components and get their target states
240
229
this . _srefs$ = new BehaviorSubject ( withHostSref ( this . _srefs . toArray ( ) ) ) ;
241
- this . _srefChangesSub = this . _srefs . changes . subscribe ( srefs => this . _srefs$ . next ( withHostSref ( srefs ) ) ) ;
230
+ this . _srefChangesSub = this . _srefs . changes . subscribe ( ( srefs ) => this . _srefs$ . next ( withHostSref ( srefs ) ) ) ;
242
231
243
232
const targetStates$ : Observable < TargetState [ ] > = this . _srefs$ . pipe (
244
- switchMap ( ( srefs : UISref [ ] ) => combineLatest < TargetState [ ] > ( srefs . map ( sref => sref . targetState$ ) ) )
233
+ switchMap ( ( srefs : UISref [ ] ) => combineLatest < TargetState [ ] > ( srefs . map ( ( sref ) => sref . targetState$ ) ) )
245
234
) ;
246
235
247
236
// Calculate the status of each UISref based on the transition event.
@@ -251,7 +240,7 @@ export class UISrefStatus {
251
240
switchMap ( ( evt : TransEvt ) => {
252
241
return targetStates$ . pipe (
253
242
map ( ( targets : TargetState [ ] ) => {
254
- const statuses : SrefStatus [ ] = targets . map ( target => getSrefStatus ( evt , target ) ) ;
243
+ const statuses : SrefStatus [ ] = targets . map ( ( target ) => getSrefStatus ( evt , target ) ) ;
255
244
return statuses . reduce ( mergeSrefStatus ) ;
256
245
} )
257
246
) ;
0 commit comments