Skip to content

Commit c21a100

Browse files
author
Anatoly Ostrovsky
committed
State directives test fixes
1 parent 4e1893e commit c21a100

31 files changed

+360
-224
lines changed

@types/animations/interface.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export type RafScheduler = {
2+
/**
3+
* Schedules a list of functions to run on the next animation frame(s).
4+
* @param tasks - The tasks to be scheduled.
5+
*/
6+
(tasks: Array<() => void>): void;
7+
/**
8+
* Internal queue of scheduled task arrays.
9+
*/
10+
queue: Array<Array<() => void>>;
11+
/**
12+
* Waits until the animation frame is quiet before running the provided function.
13+
* Cancels any previous animation frame requests.
14+
* @param fn - The function to run when the frame is quiet.
15+
*/
16+
waitUntilQuiet(fn: () => void): void;
17+
};
Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
/**
2-
* @typedef {Function} RafSchedulerFunction
3-
* @typedef {Object} RafSchedulerObject
4-
* @property {Function} waitUntilQuiet - Function to wait until the animation frame is quiet.
5-
* @typedef {RafSchedulerObject & RafSchedulerFunction} RafScheduler
2+
* @typedef {import('./interface.js').RafScheduler} RafScheduler
3+
* @typedef {import('../interface.js').ServiceProvider} ServiceProvider
64
*/
75
/**
8-
* Creates a requestAnimationFrame scheduler.
6+
* Service provider that creates a requestAnimationFrame-based scheduler.
7+
* @implements {ServiceProvider}
98
*/
10-
export function RafSchedulerProvider(): void;
11-
export class RafSchedulerProvider {
9+
export class RafSchedulerProvider implements ServiceProvider {
1210
/**
13-
* @returns {RafScheduler} The scheduler object.
11+
* Internal task queue, where each item is an array of functions to run.
12+
* @type {Array<Array<() => void>>}
1413
*/
15-
$get: () => RafScheduler;
16-
}
17-
export type RafSchedulerFunction = Function;
18-
export type RafSchedulerObject = {
14+
queue: Array<Array<() => void>>;
15+
/**
16+
* ID of the currently scheduled animation frame (if any).
17+
* Used for cancellation and tracking.
18+
* @type {number|null}
19+
*/
20+
cancelFn: number | null;
1921
/**
20-
* - Function to wait until the animation frame is quiet.
22+
* Processes the next batch of tasks in the animation frame.
23+
* Executes the first group of functions in the queue, then
24+
* schedules the next frame if needed.
2125
*/
22-
waitUntilQuiet: Function;
23-
};
24-
export type RafScheduler = RafSchedulerObject & RafSchedulerFunction;
26+
nextTick(): void;
27+
/**
28+
* Returns the scheduler function.
29+
* This function allows tasks to be queued for execution on future animation frames.
30+
* It also has helper methods and state attached.
31+
*
32+
* @returns {RafScheduler} The scheduler function with `queue` and `waitUntilQuiet`.
33+
*/
34+
$get(): RafScheduler;
35+
}
36+
export type RafScheduler = import("./interface.js").RafScheduler;
37+
export type ServiceProvider = import("../interface.js").ServiceProvider;

@types/router/directives/view-directive.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export namespace $ViewDirectiveFill {
1818
* - `name`: (Optional) A view name.
1919
* The name should be unique amongst the other views in the same state.
2020
* You can have views of the same name that live in different states.
21-
* The ng-view can be targeted in a View using the name ([[Ng1StateDeclaration.views]]).
21+
* The ng-view can be targeted in a View using the name ([[StateDeclaration.views]]).
2222
*
2323
* - `autoscroll`: an expression. When it evaluates to true, the `ng-view` will be scrolled into view when it is activated.
2424
* Uses [[$ngViewScroll]] to do the scrolling.
@@ -49,7 +49,7 @@ export namespace $ViewDirectiveFill {
4949
* ```
5050
*
5151
* The above is a convenient shortcut equivalent to specifying your view explicitly with the
52-
* [[Ng1StateDeclaration.views]] config property, by name, in this case an empty name:
52+
* [[StateDeclaration.views]] config property, by name, in this case an empty name:
5353
*
5454
* ```js
5555
* $stateProvider.state("home", {
@@ -119,7 +119,7 @@ export namespace $ViewDirectiveFill {
119119
* Resolve data:
120120
*
121121
* The resolved data from the state's `resolve` block is placed on the scope as `$resolve` (this
122-
* can be customized using [[Ng1ViewDeclaration.resolveAs]]). This can be then accessed from the template.
122+
* can be customized using [[ViewDeclaration.resolveAs]]). This can be then accessed from the template.
123123
*
124124
* Note that when `controllerAs` is being used, `$resolve` is set on the controller instance *after* the
125125
* controller is instantiated. The `$onInit()` hook can be used to perform initialization code which

@types/router/state/interface.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export interface ViewDeclaration {
6666
/**
6767
* The name of the component to use for this view.
6868
*
69-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
69+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
7070
*
7171
* The name of an [angular 1.5+ `.component()`](https://docs.angularjs.org/guide/component) (or directive with
7272
* bindToController and/or scope declaration) which will be used for this view.
@@ -119,7 +119,7 @@ export interface ViewDeclaration {
119119
/**
120120
* An object which maps `resolve`s to [[component]] `bindings`.
121121
*
122-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
122+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
123123
*
124124
* When using a [[component]] declaration (`component: 'myComponent'`), each input binding for the component is supplied
125125
* data from a resolve of the same name, by default. You may supply data from a different resolve name by mapping it here.
@@ -162,7 +162,7 @@ export interface ViewDeclaration {
162162
/**
163163
* Dynamic component provider function.
164164
*
165-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
165+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
166166
*
167167
* This is an injectable provider function which returns the name of the component to use.
168168
* The provider will invoked during a Transition in which the view's state is entered.
@@ -183,7 +183,7 @@ export interface ViewDeclaration {
183183
/**
184184
* The view's controller function or name
185185
*
186-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
186+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
187187
*
188188
* The controller function, or the name of a registered controller. The controller function will be used
189189
* to control the contents of the [[directives.uiView]] directive.
@@ -197,7 +197,7 @@ export interface ViewDeclaration {
197197
/**
198198
* A controller alias name.
199199
*
200-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
200+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
201201
*
202202
* If present, the controller will be published to scope under the `controllerAs` name.
203203
* See: https://docs.angularjs.org/api/ng/directive/ngController
@@ -206,7 +206,7 @@ export interface ViewDeclaration {
206206
/**
207207
* Dynamic controller provider function.
208208
*
209-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
209+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
210210
*
211211
* This is an injectable provider function which returns the actual controller function, or the name
212212
* of a registered controller. The provider will invoked during a Transition in which the view's state is
@@ -231,7 +231,7 @@ export interface ViewDeclaration {
231231
/**
232232
* The scope variable name to use for resolve data.
233233
*
234-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
234+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
235235
*
236236
* When a view is activated, the resolved data for the state which the view belongs to is put on the scope.
237237
* This property sets the name of the scope variable to use for the resolved data.
@@ -242,7 +242,7 @@ export interface ViewDeclaration {
242242
/**
243243
* The HTML template for the view.
244244
*
245-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
245+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
246246
*
247247
* HTML template as a string, or a function which returns an html template as a string.
248248
* This template will be used to render the corresponding [[directives.uiView]] directive.
@@ -267,7 +267,7 @@ export interface ViewDeclaration {
267267
/**
268268
* The URL for the HTML template for the view.
269269
*
270-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
270+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
271271
*
272272
* A path or a function that returns a path to an html template.
273273
* The template will be fetched and used to render the corresponding [[directives.uiView]] directive.
@@ -290,7 +290,7 @@ export interface ViewDeclaration {
290290
/**
291291
* Injected function which returns the HTML template.
292292
*
293-
* A property of [[Ng1StateDeclaration]] or [[Ng1ViewDeclaration]]:
293+
* A property of [[StateDeclaration]] or [[ViewDeclaration]]:
294294
*
295295
* Injected function which returns the HTML template.
296296
* The template will be used to render the corresponding [[directives.uiView]] directive.

@types/router/state/state-object.d.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @typedef {import('./interface.js').StateDeclaration} StateDeclaration */
12
/**
23
* Internal representation of a ng-router state.
34
*
@@ -7,9 +8,13 @@
78
*
89
* This class prototypally inherits from the corresponding [[StateDeclaration]].
910
* Each of its own properties (i.e., `hasOwnProperty`) are built using builders from the [[StateBuilder]].
11+
* @implements {StateDeclaration}
1012
*/
11-
export class StateObject {
12-
constructor(config: any);
13+
export class StateObject implements StateDeclaration {
14+
/**
15+
* @param {import('./interface.js').StateDeclaration} config
16+
*/
17+
constructor(config: import("./interface.js").StateDeclaration);
1318
name: any;
1419
navigable: any;
1520
/** @type {?StateObject} */
@@ -18,7 +23,10 @@ export class StateObject {
1823
url: any;
1924
includes: any;
2025
$$state: () => this;
21-
self: any;
26+
/**
27+
* @type {import('./interface.js').StateDeclaration}
28+
*/
29+
self: import("./interface.js").StateDeclaration;
2230
__stateObjectCache: {
2331
nameGlob: Glob;
2432
};
@@ -71,4 +79,5 @@ export namespace StateObject {
7179
/** Predicate which returns true if the object is an internal [[StateObject]] object */
7280
function isState(obj: any): boolean;
7381
}
82+
export type StateDeclaration = import("./interface.js").StateDeclaration;
7483
import { Glob } from "../common/glob.js";

@types/router/state/state-registry.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
*/
99
export class StateRegistryProvider implements ServiceProvider {
1010
static $inject: string[];
11+
/**
12+
* @param urlService
13+
* @param stateService
14+
* @param {import('../globals.js').RouterGlobals} globals
15+
* @param viewService
16+
*/
1117
constructor(
1218
urlService: any,
1319
stateService: any,
14-
globals: any,
20+
globals: import("../globals.js").RouterGlobals,
1521
viewService: any,
1622
);
1723
states: {};
@@ -26,7 +32,7 @@ export class StateRegistryProvider implements ServiceProvider {
2632
$get: import("../../interface.ts").AnnotatedFactory;
2733
/**
2834
* This is a [[StateBuilder.builder]] function for angular1 `onEnter`, `onExit`,
29-
* `onRetain` callback hooks on a [[Ng1StateDeclaration]].
35+
* `onRetain` callback hooks on a [[StateDeclaration]].
3036
*
3137
* When the [[StateBuilder]] builds a [[StateObject]] object from a raw [[StateDeclaration]], this builder
3238
* ensures that those hooks are injectable for @uirouter/angularjs (ng1).

@types/router/state/views.d.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
export function getNg1ViewConfigFactory(): (
2-
path: any,
3-
view: any,
4-
) => Ng1ViewConfig;
1+
export function getViewConfigFactory(): (path: any, view: any) => ViewConfig;
52
/**
63
* This is a [[StateBuilder.builder]] function for angular1 `views`.
74
*
@@ -13,7 +10,7 @@ export function getNg1ViewConfigFactory(): (
1310
*
1411
*/
1512
export function ng1ViewsBuilder(state: any): {};
16-
export class Ng1ViewConfig {
13+
export class ViewConfig {
1714
/**
1815
* Normalizes a view's name from a state.views configuration block.
1916
*

@types/router/transition/transition.d.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ export class Transition implements IHookRegistry {
1818
* encapsulates the "from state".
1919
* @param targetState The target state and parameters being transitioned to (also, the transition options)
2020
* @param {import('../transition/transition-service.js').TransitionProvider} transitionService The [[TransitionService]] instance
21+
* @param {import('../globals.js').RouterGlobals} globals
2122
*/
2223
constructor(
2324
fromPath: any,
2425
targetState: any,
2526
transitionService: import("../transition/transition-service.js").TransitionProvider,
26-
globals: any,
27+
globals: import("../globals.js").RouterGlobals,
2728
);
28-
globals: any;
29+
/**
30+
* @type {import('../globals.js').RouterGlobals}
31+
*/
32+
globals: import("../globals.js").RouterGlobals;
2933
transitionService: import("../transition/transition-service.js").TransitionProvider;
3034
_deferred: any;
3135
/**
@@ -67,10 +71,9 @@ export class Transition implements IHookRegistry {
6771
getHooks(hookName: any): any;
6872
applyViewConfigs(): void;
6973
/**
70-
* @internal
71-
* @returns the internal from [State] object
74+
* @returns {import('../state/state-object.js').StateObject} the internal from [State] object
7275
*/
73-
$from(): any;
76+
$from(): import("../state/state-object.js").StateObject;
7477
/**
7578
* @returns {import('../state/state-object.js').StateObject} the internal to [State] object
7679
*/
@@ -82,15 +85,15 @@ export class Transition implements IHookRegistry {
8285
*
8386
* @returns The state declaration object for the Transition's ("from state").
8487
*/
85-
from(): any;
88+
from(): import("../state/interface.ts").StateDeclaration;
8689
/**
8790
* Returns the "to state"
8891
*
8992
* Returns the state that the transition is going *to*.
9093
*
9194
* @returns The state declaration object for the Transition's target state ("to state").
9295
*/
93-
to(): any;
96+
to(): import("../state/interface.ts").StateDeclaration;
9497
/**
9598
* Gets the Target State
9699
*

@types/router/view/view.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ export class ViewService {
3838
/**
3939
* @param path
4040
* @param decl
41-
* @return {import("../state/views.js").Ng1ViewConfig}
41+
* @return {import("../state/views.js").ViewConfig}
4242
*/
4343
createViewConfig(
4444
path: any,
4545
decl: any,
46-
): import("../state/views.js").Ng1ViewConfig;
46+
): import("../state/views.js").ViewConfig;
4747
/**
4848
* Deactivates a ViewConfig.
4949
*

index.html

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
}
1515
}
1616
class TodoController {
17-
constructor($element) {
17+
constructor() {
1818
this.greeting = "Todos";
19-
this.counter = 123;
20-
this.name = "dfsf";
2119
this.model = {
2220
name: "John",
2321
lastName: "Doe",
@@ -26,7 +24,6 @@
2624
new Todo("Learn AngularTS"),
2725
new Todo("Build an AngularTS app"),
2826
];
29-
window.test = this;
3027
}
3128

3229
get() {
@@ -64,13 +61,7 @@
6461
window.angular
6562
.module("todo", [])
6663
.controller("TodoCtrl", TodoController)
67-
.controller("DemoCtrl", Demo)
68-
.run(($rootScope) => {
69-
$rootScope.model = [
70-
{ name: "a", item: ["a1", "a2"] },
71-
{ name: "b", item: ["b1", "b2"] },
72-
];
73-
});
64+
.controller("DemoCtrl", Demo);
7465
});
7566
</script>
7667
</head>

0 commit comments

Comments
 (0)