Skip to content

Commit d849df6

Browse files
docs(Glob): Document state globs
Closes #2963 Closes #2965
1 parent 82b9491 commit d849df6

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

src/common/glob.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,49 @@
11
/** @module common */
22
/**
3-
* Matches state names using glob-like patterns.
4-
*
5-
* See: [[StateService.includes]]
3+
* Matches state names using glob-like pattern strings.
4+
*
5+
* Globs can be used in specific APIs including:
6+
*
7+
* - [[StateService.is]]
8+
* - [[StateService.includes]]
9+
* - [[HookMatchCriteria.to]]
10+
* - [[HookMatchCriteria.from]]
11+
* - [[HookMatchCriteria.exiting]]
12+
* - [[HookMatchCriteria.retained]]
13+
* - [[HookMatchCriteria.entering]]
14+
*
15+
* A `Glob` string is a pattern which matches state names according to the following rules:
16+
*
17+
* ### Exact match:
18+
*
19+
* The glob `'A.B'` matches the state named exactly `'A.B'`.
20+
*
21+
* | Glob |Matches states named|Does not match state named|
22+
* |:------------|:--------------------|:-----------------|
23+
* | `'A'` | `'A'` | `'B'` , `'A.C'` |
24+
* | `'A.B'` | `'A.B'` | `'A'` , `'A.B.C'`|
25+
*
26+
* ### Single wildcard (`*`)
27+
*
28+
* A single wildcard (`*`) matches any value for *a single segment* of a state name.
29+
*
30+
* | Glob |Matches states named |Does not match state named |
31+
* |:------------|:---------------------|:--------------------------|
32+
* | `'A.*'` | `'A.B'` , `'A.C'` | `'A'` , `'A.B.C'` |
33+
* | `'*'` | `'A'` , `'Z'` | `'A.B'` , `'Z.Y.X'` |
34+
* | `'A.*.*'` | `'A.B.C'` , `'A.X.Y'`| `'A'`, `'A.B'` , `'Z.Y.X'`|
35+
*
36+
*
37+
* ### Double wildcards (`**`)
38+
*
39+
* Double wildcards (`'**'`) act as a wildcard for *one or more segments*
40+
*
41+
* | Glob |Matches states named |Does not match state named|
42+
* |:------------|:----------------------------------------------|:-------------------------|
43+
* | `'**'` | `'A'` , `'A.B'`, `'Z.Y.X'` | (matches all states) |
44+
* | `'A.**'` | `'A.B'` , `'A.C'` , `'A.B.X'` | `'A'`, `'Z.Y.X'` |
45+
* | `'**.login'`| `'A.login'` , `'A.B.login'` , `'Z.Y.X.login'` | `'A'` , `'login'` , `'A.login.Z'` |
46+
*
647
*/
748
export class Glob {
849
text: string;

src/transition/interface.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ export interface IHookRegistry {
268268
* See [[TransitionHookFn]] for the signature of the function.
269269
*
270270
* The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
271+
* To match all Transitions, use an empty criteria object `{}`.
271272
*
272273
* ### Lifecycle
273274
*
@@ -364,6 +365,7 @@ export interface IHookRegistry {
364365
* See [[TransitionHookFn]] for the signature of the function.
365366
*
366367
* The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
368+
* To match all Transitions, use an empty criteria object `{}`.
367369
*
368370
* ### Lifecycle
369371
*
@@ -397,7 +399,7 @@ export interface IHookRegistry {
397399
* @example
398400
* ```js
399401
* // ng1
400-
* $transitions.onStart( { to: 'auth.*' }, function(trans) {
402+
* $transitions.onStart( { to: 'auth.**' }, function(trans) {
401403
* var $state = trans.router.stateService;
402404
* var MyAuthService = trans.injector().get('MyAuthService');
403405
*
@@ -436,9 +438,7 @@ export interface IHookRegistry {
436438
*
437439
* The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
438440
* `onEnter` hooks generally specify `{ entering: 'somestate' }`.
439-
*
440-
* The `matchCriteria` is used to determine which Transitions the hook should be invoked during.
441-
* Note: for `onEnter` hooks, the `to` in the `matchCriteria` matches the entering state, not the Transition "to state".
441+
* To match all Transitions, use an empty criteria object `{}`.
442442
*
443443
* ### Lifecycle
444444
*
@@ -508,8 +508,9 @@ export interface IHookRegistry {
508508
* This hook can be used to perform actions when the user moves from one substate to another, such as
509509
* between steps in a wizard.
510510
*
511-
* The `matchCriteria` is used to determine which Transitions the hook should be invoked during.
511+
* The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
512512
* `onRetain` hooks generally specify `{ retained: 'somestate' }`.
513+
* To match all Transitions, use an empty criteria object `{}`.
513514
*
514515
* ### Lifecycle
515516
*
@@ -548,6 +549,7 @@ export interface IHookRegistry {
548549
*
549550
* The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
550551
* `onExit` hooks generally specify `{ exiting: 'somestate' }`.
552+
* To match all Transitions, use an empty criteria object `{}`.
551553
*
552554
* ### Lifecycle
553555
*
@@ -583,6 +585,7 @@ export interface IHookRegistry {
583585
* See [[TransitionHookFn]] for the signature of the function.
584586
*
585587
* The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
588+
* To match all Transitions, use an empty criteria object `{}`.
586589
*
587590
* ### Lifecycle
588591
*
@@ -609,6 +612,7 @@ export interface IHookRegistry {
609612
* See [[TransitionHookFn]] for the signature of the function.
610613
*
611614
* The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
615+
* To match all Transitions, use an empty criteria object `{}`.
612616
*
613617
* ### Lifecycle
614618
*
@@ -635,6 +639,7 @@ export interface IHookRegistry {
635639
* See [[TransitionHookFn]] for the signature of the function.
636640
*
637641
* The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
642+
* To match all Transitions, use an empty criteria object `{}`.
638643
*
639644
* ### Lifecycle
640645
*
@@ -689,10 +694,11 @@ export type IStateMatch = Predicate<State>
689694
* This object is used to configure whether or not a Transition Hook is invoked for a particular transition,
690695
* based on the Transition's "to state" and "from state".
691696
*
692-
* Each property (`to`, `from`, `exiting`, `retained`, and `entering`) can be state globs, a function that takes a
693-
* state, or a boolean (see [[HookMatchCriterion]])
697+
* Each property (`to`, `from`, `exiting`, `retained`, and `entering`) can be a state [[Glob]] string,
698+
* a boolean, or a function that takes a state and returns a boolean (see [[HookMatchCriterion]])
694699
*
695700
* All properties are optional. If any property is omitted, it is replaced with the value `true`, and always matches.
701+
* To match any transition, use an empty criteria object `{}`.
696702
*
697703
* @example
698704
* ```js
@@ -774,7 +780,7 @@ export interface IMatchingNodes {
774780
* Or, a function with the signature `function(state) { return matches; }`
775781
* which should return a boolean to indicate if a state matches.
776782
*
777-
* Or, `true` to match anything
783+
* Or, `true` to always match
778784
*/
779785
export type HookMatchCriterion = (string|IStateMatch|boolean)
780786

0 commit comments

Comments
 (0)