@@ -8,35 +8,131 @@ var __ignore_me = global;
88
99
1010/**
11- * Defines route lifecycle method [onActivate]
11+ * Defines route lifecycle method [onActivate], which is called by the router at the end of a
12+ * successful route navigation.
13+ *
14+ * For a single component's navigation, only one of either [onActivate] or [onReuse] will be called,
15+ * depending on the result of [canReuse].
16+ *
17+ * If `onActivate` returns a promise, the route change will wait until the promise settles to
18+ * instantiate and activate child components.
19+ *
20+ * ## Example
21+ * ```
22+ * @Directive ({
23+ * selector: 'my-cmp'
24+ * })
25+ * class MyCmp implements OnActivate {
26+ * onActivate(next, prev) {
27+ * this.log = 'Finished navigating from ' + prev.urlPath + ' to ' + next.urlPath;
28+ * }
29+ * }
30+ * ```
1231 */
1332export interface OnActivate {
1433 onActivate ( nextInstruction : ComponentInstruction , prevInstruction : ComponentInstruction ) : any ;
1534}
1635
1736/**
18- * Defines route lifecycle method [onReuse]
37+ * Defines route lifecycle method [onReuse], which is called by the router at the end of a
38+ * successful route navigation when [canReuse] is implemented and returns or resolves to true.
39+ *
40+ * For a single component's navigation, only one of either [onActivate] or [onReuse] will be called,
41+ * depending on the result of [canReuse].
42+ *
43+ * ## Example
44+ * ```
45+ * @Directive ({
46+ * selector: 'my-cmp'
47+ * })
48+ * class MyCmp implements CanReuse, OnReuse {
49+ * canReuse() {
50+ * return true;
51+ * }
52+ *
53+ * onReuse(next, prev) {
54+ * this.params = next.params;
55+ * }
56+ * }
57+ * ```
1958 */
2059export interface OnReuse {
2160 onReuse ( nextInstruction : ComponentInstruction , prevInstruction : ComponentInstruction ) : any ;
2261}
2362
2463/**
25- * Defines route lifecycle method [onDeactivate]
64+ * Defines route lifecycle method [onDeactivate], which is called by the router before destroying
65+ * a component as part of a route change.
66+ *
67+ * If `onDeactivate` returns a promise, the route change will wait until the promise settles.
68+ *
69+ * ## Example
70+ * ```
71+ * @Directive ({
72+ * selector: 'my-cmp'
73+ * })
74+ * class MyCmp implements CanReuse, OnReuse {
75+ * canReuse() {
76+ * return true;
77+ * }
78+ *
79+ * onReuse(next, prev) {
80+ * this.params = next.params;
81+ * }
82+ * }
83+ * ```
2684 */
2785export interface OnDeactivate {
2886 onDeactivate ( nextInstruction : ComponentInstruction , prevInstruction : ComponentInstruction ) : any ;
2987}
3088
3189/**
32- * Defines route lifecycle method [canReuse]
90+ * Defines route lifecycle method [canReuse], which is called by the router to determine whether a
91+ * component should be reused across routes, or whether to destroy and instantiate a new component.
92+ *
93+ * If `canReuse` returns or resolves to `true`, the component instance will be reused.
94+ *
95+ * If `canReuse` throws or rejects, the navigation will be cancelled.
96+ *
97+ * ## Example
98+ * ```
99+ * @Directive ({
100+ * selector: 'my-cmp'
101+ * })
102+ * class MyCmp implements CanReuse, OnReuse {
103+ * canReuse(next, prev) {
104+ * return next.params.id == prev.params.id;
105+ * }
106+ *
107+ * onReuse(next, prev) {
108+ * this.id = next.params.id;
109+ * }
110+ * }
111+ * ```
33112 */
34113export interface CanReuse {
35114 canReuse ( nextInstruction : ComponentInstruction , prevInstruction : ComponentInstruction ) : any ;
36115}
37116
38117/**
39- * Defines route lifecycle method [canDeactivate]
118+ * Defines route lifecycle method [canDeactivate], which is called by the router to determine
119+ * if a component can be removed as part of a navigation.
120+ *
121+ * If `canDeactivate` returns or resolves to `false`, the navigation is cancelled.
122+ *
123+ * If `canDeactivate` throws or rejects, the navigation is also cancelled.
124+ *
125+ * ## Example
126+ * ```
127+ * @Directive ({
128+ * selector: 'my-cmp'
129+ * })
130+ * class MyCmp implements CanDeactivate {
131+ * canDeactivate(next, prev) {
132+ * return askUserIfTheyAreSureTheyWantToQuit();
133+ * }
134+ * }
135+ * ```
40136 */
41137export interface CanDeactivate {
42138 canDeactivate ( nextInstruction : ComponentInstruction , prevInstruction : ComponentInstruction ) : any ;
0 commit comments