Skip to content

Commit 25f8a9f

Browse files
chore(*): Added some more typing information
1 parent e31e14d commit 25f8a9f

File tree

10 files changed

+89
-46
lines changed

10 files changed

+89
-46
lines changed

src/common/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function indexOf(array, value) {
9999
return -1;
100100
}
101101

102-
export const removeFrom = (array) => (obj) => {
102+
export const removeFrom = (array: any[]) => (obj) => {
103103
var idx = array.indexOf(obj);
104104
if (idx >= 0) array.splice(idx, 1);
105105
return array;
@@ -379,7 +379,7 @@ export function isEq(fn1: F, fn2: F): () => boolean {
379379
};
380380
}
381381

382-
export function val(v): F {
382+
export function val<T>(v: T): () => T {
383383
return function() { return v; };
384384
}
385385

src/interface.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {UrlMatcher} from "url/urlMatcher";
2+
import {ParamSet} from "params/paramSet";
3+
4+
/** View declaration inside state declaration */
5+
export interface IViewDeclaration {
6+
controllerProvider?: Function;
7+
controller?: any;
8+
template?: any;
9+
templateUrl?: any;
10+
templateProvider?: Function;
11+
}
12+
13+
/** hash of strings->views */
14+
interface IViewDeclarations { [key:string]: IViewDeclaration; }
15+
/** hash of strings->resolve fns */
16+
interface IResolveDeclarations { [key:string]: Function; }
17+
/** hash of strings->param declarations */
18+
// If the value is of type 'any', then it is syntax sugar for an IParamDeclaration { value: value }
19+
interface IParamsDeclaration { [key:string]: (IParamDeclaration|any) }
20+
/** declaration of single state param */
21+
interface IParamDeclaration {
22+
value: any;
23+
squash: (boolean|string);
24+
}
25+
26+
/** state declaration */
27+
export interface IStateDeclaration extends IViewDeclaration {
28+
name: string;
29+
abstract: boolean;
30+
parent: (string|IStateDeclaration);
31+
resolve: IResolveDeclarations; // name->Function
32+
resolvePolicy: (string|Object);
33+
url: string;
34+
params: IParamsDeclaration;
35+
views: IViewDeclarations;
36+
data: any;
37+
// TODO: finish defining state definition API. Maybe start with what's on Definitely Typed.
38+
}
39+
40+
/** internal state API */
41+
export interface IState {
42+
name: string;
43+
abstract: boolean;
44+
parent: IState;
45+
resolve: IResolveDeclarations; // name->Function
46+
resolvePolicy: (string|Object);
47+
url: UrlMatcher;
48+
params: ParamSet;
49+
ownParams: ParamSet;
50+
views: IViewDeclarations;
51+
self: IStateDeclaration;
52+
root: () => IState;
53+
navigable: IState;
54+
path: IState[];
55+
data: any;
56+
includes: (name: string) => boolean;
57+
}

src/resolve/path.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {extend, isArray, identity, noop} from "../common/common";
44
import {defaults, map, omit, pluck, find, pipe, prop, eq} from "../common/common";
55
import {trace} from "../common/trace";
66
import {IPromise} from "angular";
7-
import {IPublicState} from "../state/state";
7+
import {IState} from "../interface";
88
import {runtime} from "../common/angular1"
99
import PathElement from "./pathElement";
1010
import Resolvable from "./resolvable";
@@ -25,7 +25,7 @@ import Resolvable from "./resolvable";
2525
*/
2626

2727
class Path {
28-
constructor(statesOrPathElements: (IPublicState[] | PathElement[])) {
28+
constructor(statesOrPathElements: (IState[] | PathElement[])) {
2929
if (!isArray(statesOrPathElements))
3030
throw new Error("states must be an array of state(s) or PathElement(s): ${statesOrPathElements}");
3131

@@ -101,11 +101,11 @@ class Path {
101101
return this;
102102
}
103103

104-
states(): IPublicState[] {
104+
states(): IState[] {
105105
return pluck(this.elements, "state");
106106
}
107107

108-
elementForState(state: IPublicState): PathElement {
108+
elementForState(state: IState): PathElement {
109109
return find(this.elements, pipe(prop('state'), eq(state)));
110110
}
111111

src/resolve/pathElement.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {isObject, isString, extend, forEach, noop, pick, map, filter, parse} from "../common/common";
44
import {trace} from "../common/trace";
55
import {IPromise} from "angular";
6-
import {IPublicState} from "../state/state";
6+
import {IState} from "../interface";
77
import Path from "./path";
88
import Resolvable from "./resolvable";
99
import {runtime} from "../common/angular1"
@@ -23,15 +23,15 @@ var defaultResolvePolicy = "jit"; // TODO: make this configurable
2323
* on the fly.
2424
*/
2525
export default class PathElement {
26-
constructor(state: IPublicState) {
26+
constructor(state: IState) {
2727
this.state = state;
2828
// Convert state's resolvable assoc-array into an assoc-array of empty Resolvable(s)
2929
this._resolvables = map(state.resolve || {}, function(resolveFn, resolveName) {
3030
return new Resolvable(resolveName, resolveFn, state);
3131
});
3232
}
3333

34-
state: IPublicState;
34+
state: IState;
3535
private _resolvables: Object;
3636

3737
getResolvables(): Object {

src/resolve/resolvable.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {pick, map} from "../common/common";
44
import {trace} from "../common/trace";
55
import {IPromise} from "angular";
6-
import {IPublicState} from "../state/state";
6+
import {IState} from "../interface";
77
import {runtime} from "../common/angular1"
88

99
/**
@@ -19,7 +19,7 @@ import {runtime} from "../common/angular1"
1919
* parameter to those fns.
2020
*/
2121
class Resolvable {
22-
constructor(name: string, resolveFn: Function, state: IPublicState) {
22+
constructor(name: string, resolveFn: Function, state: IState) {
2323
this.name = name;
2424
this.resolveFn = resolveFn;
2525
this.state = state;
@@ -28,7 +28,7 @@ class Resolvable {
2828

2929
name: String;
3030
resolveFn: Function;
31-
state: IPublicState;
31+
state: IState;
3232
deps: string[];
3333

3434
promise: IPromise<any> = undefined;

src/state/state.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,14 @@ import {defaultTransOpts} from "../transition/transitionService";
77
import {Param} from "../params/param";
88
import {ParamSet} from "../params/paramSet";
99
import {IServiceProviderFactory} from "angular";
10-
11-
export interface IPublicState {
12-
name: string;
13-
resolve: any; // key->Function
14-
url: string;
15-
resolvePolicy: (string|Object);
16-
// TODO: finish defining state API. Maybe start with what's on Definitely Typed.
17-
}
18-
19-
export interface IState {
20-
name: string;
21-
resolve: any; // key->Function
22-
url: string;
23-
resolvePolicy: (string|Object);
24-
self: IPublicState;
25-
params: ParamSet;
26-
root(): IState;
27-
path: IState[];
28-
// TODO: finish defining state API. Maybe start with what's on Definitely Typed.
29-
}
30-
10+
import {UrlMatcher} from "../url/urlMatcher";
11+
import {IState, IStateDeclaration} from "../interface";
3112

3213
export function StateQueueManager(states, builder, $urlRouterProvider, $state) {
3314
var queue = [];
3415

3516
var queueManager = extend(this, {
36-
register: function(config: IPublicState, pre?: boolean) {
17+
register: function(config: IStateDeclaration, pre?: boolean) {
3718
// Wrap a new object around the state so we can store our private details easily.
3819
var state = inherit(new State(), extend({}, config, {
3920
self: config,
@@ -307,7 +288,7 @@ export function StateMatcher(states) {
307288
*
308289
* @returns {Object} Returns a new `State` object.
309290
*/
310-
function State(config?: IPublicState) {
291+
function State(config?: IStateDeclaration) {
311292
extend(this, config);
312293
}
313294

@@ -406,7 +387,7 @@ export class StateReference {
406387
return this._definition;
407388
}
408389

409-
state(): IPublicState {
390+
state(): IStateDeclaration {
410391
return this._definition && this._definition.self;
411392
}
412393

src/transition/transition.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import Resolvable from "../resolve/resolvable";
1111
import Path from "../resolve/path";
1212
import PathElement from "../resolve/pathElement";
1313
import {RejectFactory} from "./rejectFactory"
14-
import {StateParams, StateReference, IState, IPublicState} from "../state/state";
14+
import {StateParams, StateReference} from "../state/state"
15+
import {IState, IStateDeclaration} from "../interface";
1516
import {ViewContext} from "../view/viewContext";
1617
import {StateViewConfig} from "../view/view";
1718
import {defaults, eq, extend, filter, flatten, forEach, identity, invoke, is, isEq, isFunction, isObject, isPromise, isDefined,
@@ -262,6 +263,10 @@ export class Transition {
262263
return new ViewContext(pathElement, this._treeChanges.to, this._options, runtime.$injector);
263264
}
264265

266+
/**
267+
* Returns a list of StateViewConfig objects;
268+
* Returns one StateViewConfig for each view in each state in a named path of the transition's tree changes
269+
*/
265270
views(pathname: string = "entering") {
266271
var path = this._treeChanges[pathname];
267272
var states = states || path.states();
@@ -338,7 +343,7 @@ export class Transition {
338343
var options = this._options;
339344
var tLocals = {$transition$: this};
340345

341-
var rootPE = new PathElement(this._from.$state().root().self);
346+
var rootPE = new PathElement(this._from.$state().root());
342347
var rootPath = new Path([rootPE]);
343348
var exitingElements = exiting.slice(0).reverse().elements;
344349
var enteringElements = entering.elements;

src/transition/transitionHook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {RejectFactory} from "./rejectFactory";
44
import PathElement from "../resolve/pathElement";
55
import Path from "../resolve/path";
66
import {Transition} from "./transition";
7-
import {IPublicState} from "../state/state";
7+
import {IState} from "../interface";
88
import Resolvable from "../resolve/resolvable";
99

1010
var REJECT = new RejectFactory();
@@ -23,7 +23,7 @@ export default class TransitionHook {
2323
// TODO these are redundant, check why we're doubling up on them.
2424
async: boolean;
2525
rejectIfSuperseded: boolean;
26-
state: IPublicState;
26+
state: IState;
2727
data: any;
2828

2929
constructor(pathElement: PathElement, fn: Function, locals: any, pathContext: Path, options: any) {

src/transition/transitionService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import {IServiceProviderFactory} from "angular";
44
import {Transition} from "./transition";
55
import {Glob} from "../state/glob";
6-
import {IPublicState, IState} from "../state/state";
6+
import {IStateDeclaration, IState} from "../interface";
77
import {extend, is, isFunction, isString, val, noop} from "../common/common";
88

99
export interface ITransitionOptions {
1010
location ?: boolean,
11-
relative ?: (boolean|IPublicState|IState),
11+
relative ?: (boolean|IStateDeclaration|IState),
1212
inherit ?: boolean,
1313
notify ?: boolean,
14-
reload ?: (boolean|string|IPublicState|IState),
14+
reload ?: (boolean|string|IStateDeclaration|IState),
1515
reloadState ?: (IState),
1616
trace ?: boolean,
1717
custom ?: any,

src/view/viewContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import Path from "../resolve/path";
22
import PathElement from "../resolve/pathElement";
3-
import {IPublicState} from "../state/state";
3+
import {IState} from "../interface";
44
import {objectKeys, zipObject, pick} from "../common/common";
55

66
export class ViewContext {
7-
state: IPublicState;
7+
//state: IState;
88
_pathElement: PathElement;
99
_path: Path;
1010
_options: any;
1111
_injector: ng.auto.IInjectorService;
1212

1313
constructor(pathElement: PathElement, path: Path, options: any, $injector: ng.auto.IInjectorService) {
14-
this.state = pathElement.state;
14+
//this.state = pathElement.state;
1515
this._pathElement = pathElement;
1616
this._path = path;
1717
this._options = options;

0 commit comments

Comments
 (0)