Skip to content

Commit feceaf9

Browse files
feat(StateObject): Rename internal State object to StateObject
BREAKING CHANGE: Renamed internal API `State` object to `StateObject` - #### Before: ``` import {State} from "ui-router-core"; ``` - #### Now: ``` import {StateObject} from "ui-router-core"; ``` - #### Motivation: We'd like to use the `State` name/symbol as a public API. It will be an ES7/TS decorator for ES6/TS state definition classes, i.e: ```js @State("foo") export class FooState implements StateDeclaration { url = "/foo"; component = FooComponent; @resolve({ deps: [FooService] }) fooData(fooService) { return fooService.getFoos(); } } ``` - #### BC Likelihood How likely is this to affect me? Low: This only affects code that imports the internal API symbol `State`. You will likely be affected you 1) import that symbol, 2) are using typescript and 3) explicitly typed a variable such as `let internalStateObject = state.$$state();` - #### BC Severity How severe is this change? Low: Find all places where `State` is imported and rename to `StateObject`
1 parent 642df0b commit feceaf9

30 files changed

+124
-124
lines changed

src/common/common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { isFunction, isString, isArray, isRegExp, isDate, isDefined } from "./predicates";
1111
import { all, any, prop, curry, val, not } from "./hof";
1212
import { services } from "./coreservices";
13-
import { State } from "../state/stateObject";
13+
import { StateObject } from "../state/stateObject";
1414

1515
let w: any = typeof window === 'undefined' ? {} : window;
1616
let angular = w.angular || {};
@@ -222,8 +222,8 @@ export const mergeR = (memo: Obj, item: Obj) => extend(memo, item);
222222
* @param {Object} second The second state.
223223
* @return {Array} Returns an array of state names in descending order, not including the root.
224224
*/
225-
export function ancestors(first: State, second: State) {
226-
let path: State[] = [];
225+
export function ancestors(first: StateObject, second: StateObject) {
226+
let path: StateObject[] = [];
227227

228228
for (var n in first.path) {
229229
if (first.path[n] !== second.path[n]) break;

src/common/predicates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/** */
99
import { and, not, pipe, prop, or } from "./hof";
1010
import { Predicate } from "./common"; // has or is using
11-
import { State } from "../state/stateObject";
11+
import { StateObject } from "../state/stateObject";
1212

1313
const toStr = Object.prototype.toString;
1414
const tis = (t: string) => (x: any) => typeof(x) === t;
@@ -23,7 +23,7 @@ export const isObject = (x: any) => x !== null && typeof x === 'object';
2323
export const isArray = Array.isArray;
2424
export const isDate: (x: any) => x is Date = <any> ((x: any) => toStr.call(x) === '[object Date]');
2525
export const isRegExp: (x: any) => x is RegExp = <any> ((x: any) => toStr.call(x) === '[object RegExp]');
26-
export const isState: (x: any) => x is State = State.isState;
26+
export const isState: (x: any) => x is StateObject = StateObject.isState;
2727

2828
/**
2929
* Predicate which checks if a value is injectable

src/common/trace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {PathNode} from "../path/node";
4343
import {PolicyWhen} from "../resolve/interface";
4444
import {TransitionHook} from "../transition/transitionHook";
4545
import {HookResult} from "../transition/interface";
46-
import {State} from "../state/stateObject";
46+
import {StateObject} from "../state/stateObject";
4747

4848
/** @hidden */
4949
function uiViewString (viewData: ActiveUIView) {
@@ -193,7 +193,7 @@ export class Trace {
193193
}
194194

195195
/** @internalapi called by ui-router code */
196-
traceSuccess(finalState: State, trans: Transition) {
196+
traceSuccess(finalState: StateObject, trans: Transition) {
197197
if (!this.enabled(Category.TRANSITION)) return;
198198
console.log(`${transLbl(trans)}: <- Success ${stringify(trans)}, final state: ${finalState.name}`);
199199
}

src/globals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/ /** */
55
import {StateParams} from "./params/stateParams";
66
import {StateDeclaration} from "./state/interface";
7-
import {State} from "./state/stateObject";
7+
import {StateObject} from "./state/stateObject";
88
import {Transition} from "./transition/transition";
99
import {Queue} from "./common/queue";
1010
import {TransitionService} from "./transition/transitionService";
@@ -38,7 +38,7 @@ export class UIRouterGlobals implements Disposable {
3838
* The to-state from the latest successful transition
3939
* @internalapi
4040
*/
41-
$current: State;
41+
$current: StateObject;
4242

4343
/**
4444
* The current transition (in progress)

src/hooks/onEnterExitRetain.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @module hooks */ /** for typedoc */
22
import {TransitionStateHookFn} from "../transition/interface";
3-
import {State} from "../state/stateObject";
3+
import {StateObject} from "../state/stateObject";
44
import {Transition} from "../transition/transition";
55
import {TransitionService} from "../transition/transitionService";
66

@@ -13,7 +13,7 @@ import {TransitionService} from "../transition/transitionService";
1313
* @hidden
1414
*/
1515
function makeEnterExitRetainHook(hookName: string): TransitionStateHookFn {
16-
return (transition: Transition, state: State) => {
16+
return (transition: Transition, state: StateObject) => {
1717
let hookFn: TransitionStateHookFn = state[hookName];
1818
return hookFn(transition, state);
1919
}

src/hooks/resolve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @module hooks */ /** for typedoc */
22
import {noop} from "../common/common";
33
import {Transition} from "../transition/transition";
4-
import {State} from "../state/stateObject";
4+
import {StateObject} from "../state/stateObject";
55
import {ResolveContext} from "../resolve/resolveContext";
66
import {TransitionStateHookFn, TransitionHookFn} from "../transition/interface";
77
import {TransitionService} from "../transition/transitionService";
@@ -33,7 +33,7 @@ export const registerEagerResolvePath = (transitionService: TransitionService) =
3333
*
3434
* See [[StateDeclaration.resolve]]
3535
*/
36-
const lazyResolveState: TransitionStateHookFn = (trans: Transition, state: State) =>
36+
const lazyResolveState: TransitionStateHookFn = (trans: Transition, state: StateObject) =>
3737
new ResolveContext(trans.treeChanges().to)
3838
.subContext(state)
3939
.resolvePath("LAZY", trans)

src/params/stateParams.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
/** */
66
import {extend, ancestors, Obj} from "../common/common";
7-
import {State} from "../state/stateObject";
7+
import {StateObject} from "../state/stateObject";
88

99
/** @internalapi */
1010
export class StateParams {
@@ -22,7 +22,7 @@ export class StateParams {
2222
* @param {Object} $current Internal definition of object representing the current state.
2323
* @param {Object} $to Internal definition of object representing state to transition to.
2424
*/
25-
$inherit(newParams: Obj, $current: State, $to: State) {
25+
$inherit(newParams: Obj, $current: StateObject, $to: StateObject) {
2626
let parents = ancestors($current, $to),
2727
parentParams: string[],
2828
inherited: Obj = {},

src/path/node.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @module path */ /** for typedoc */
22
import {extend, applyPairs, find, allTrueR} from "../common/common";
33
import {propEq} from "../common/hof";
4-
import {State} from "../state/stateObject";
4+
import {StateObject} from "../state/stateObject";
55
import {RawParams} from "../params/interface";
66
import {Param} from "../params/param";
77
import {Resolvable} from "../resolve/resolvable";
@@ -16,7 +16,7 @@ import {ViewConfig} from "../view/interface";
1616
*/
1717
export class PathNode {
1818
/** The state being entered, exited, or retained */
19-
public state: State;
19+
public state: StateObject;
2020
/** The parameters declared on the state */
2121
public paramSchema: Param[];
2222
/** The parameter values that belong to the state */
@@ -29,7 +29,7 @@ export class PathNode {
2929
/** Creates a copy of a PathNode */
3030
constructor(state: PathNode);
3131
/** Creates a new (empty) PathNode for a State */
32-
constructor(state: State);
32+
constructor(state: StateObject);
3333
constructor(stateOrPath: any) {
3434
if (stateOrPath instanceof PathNode) {
3535
let node: PathNode = stateOrPath;
@@ -39,7 +39,7 @@ export class PathNode {
3939
this.resolvables = node.resolvables.slice();
4040
this.views = node.views && node.views.slice();
4141
} else {
42-
let state: State = stateOrPath;
42+
let state: StateObject = stateOrPath;
4343
this.state = state;
4444
this.paramSchema = state.parameters({ inherit: false });
4545
this.paramValues = {};

src/path/pathFactory.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {TreeChanges} from "../transition/interface";
88
import {ViewConfig} from "../view/interface";
99
import {_ViewDeclaration} from "../state/interface";
1010

11-
import {State} from "../state/stateObject";
11+
import {StateObject} from "../state/stateObject";
1212
import {TargetState} from "../state/targetState";
1313
import {PathNode} from "../path/node";
1414
import {ViewService} from "../view/view";
@@ -45,7 +45,7 @@ export class PathFactory {
4545
*
4646
* On each [[PathNode]], creates ViewConfig objects from the views: property of the node's state
4747
*/
48-
static applyViewConfigs($view: ViewService, path: PathNode[], states: State[]) {
48+
static applyViewConfigs($view: ViewService, path: PathNode[], states: StateObject[]) {
4949
// Only apply the viewConfigs to the nodes for the given states
5050
path.filter(node => inArray(states, node.state)).forEach(node => {
5151
let viewDecls: _ViewDeclaration[] = values(node.state.views || {});
@@ -67,7 +67,7 @@ export class PathFactory {
6767
* it is not inherited from the fromPath.
6868
*/
6969
static inheritParams(fromPath: PathNode[], toPath: PathNode[], toKeys: string[] = []): PathNode[] {
70-
function nodeParamVals(path: PathNode[], state: State): RawParams {
70+
function nodeParamVals(path: PathNode[], state: StateObject): RawParams {
7171
let node: PathNode = find(path, propEq('state', state));
7272
return extend({}, node && node.paramValues);
7373
}
@@ -100,9 +100,9 @@ export class PathFactory {
100100
/**
101101
* Computes the tree changes (entering, exiting) between a fromPath and toPath.
102102
*/
103-
static treeChanges(fromPath: PathNode[], toPath: PathNode[], reloadState: State): TreeChanges {
103+
static treeChanges(fromPath: PathNode[], toPath: PathNode[], reloadState: StateObject): TreeChanges {
104104
let keep = 0, max = Math.min(fromPath.length, toPath.length);
105-
const staticParams = (state: State) =>
105+
const staticParams = (state: StateObject) =>
106106
state.parameters({ inherit: false }).filter(not(prop('dynamic'))).map(prop('id'));
107107
const nodesMatch = (node1: PathNode, node2: PathNode) =>
108108
node1.equals(node2, staticParams(node1.state));

src/resolve/resolvable.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {ResolveContext} from "./resolveContext";
1111
import {stringify} from "../common/strings";
1212
import {isFunction, isObject} from "../common/predicates";
1313
import {Transition} from "../transition/transition";
14-
import {State} from "../state/stateObject";
14+
import {StateObject} from "../state/stateObject";
1515
import {PathNode} from "../path/node";
1616

1717

@@ -90,7 +90,7 @@ export class Resolvable implements ResolvableLiteral {
9090
}
9191
}
9292

93-
getPolicy(state:State): ResolvePolicy {
93+
getPolicy(state:StateObject): ResolvePolicy {
9494
let thisPolicy = this.policy || {};
9595
let statePolicy = state && state.resolvePolicy || {};
9696
return {
@@ -133,7 +133,7 @@ export class Resolvable implements ResolvableLiteral {
133133

134134
// If the resolve policy is RXWAIT, wait for the observable to emit something. otherwise pass through.
135135
let node: PathNode = resolveContext.findNode(this);
136-
let state: State = node && node.state;
136+
let state: StateObject = node && node.state;
137137
let maybeWaitForRx = this.getPolicy(state).async === "RXWAIT" ? waitForRx : identity;
138138

139139
// After the final value has been resolved, update the state of the Resolvable

src/resolve/resolveContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { services, $InjectorLike } from "../common/coreservices";
77
import { resolvePolicies, PolicyWhen, ResolvePolicy } from "./interface";
88
import { PathNode } from "../path/node";
99
import { Resolvable } from "./resolvable";
10-
import { State } from "../state/stateObject";
10+
import { StateObject } from "../state/stateObject";
1111
import { PathFactory } from "../path/pathFactory";
1212
import { stringify } from "../common/strings";
1313
import { Transition } from "../transition/transition";
@@ -81,7 +81,7 @@ export class ResolveContext {
8181
* When resolving for the `B` node, first take the full "To Path" Context `[A,B,C,D]` and limit to the subpath `[A,B]`.
8282
* `let AB = ABCD.subcontext(a)`
8383
*/
84-
subContext(state: State): ResolveContext {
84+
subContext(state: StateObject): ResolveContext {
8585
return new ResolveContext(PathFactory.subPath(this._path, node => node.state === state));
8686
}
8787

@@ -100,7 +100,7 @@ export class ResolveContext {
100100
* @param newResolvables the new Resolvables
101101
* @param state Used to find the node to put the resolvable on
102102
*/
103-
addResolvables(newResolvables: Resolvable[], state: State) {
103+
addResolvables(newResolvables: Resolvable[], state: StateObject) {
104104
let node = <PathNode> find(this._path, propEq('state', state));
105105
let keys = newResolvables.map(r => r.token);
106106
node.resolvables = node.resolvables.filter(r => keys.indexOf(r.token) === -1).concat(newResolvables);

src/state/interface.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @module state
44
*/ /** for typedoc */
55
import { ParamDeclaration, RawParams, ParamsOrArray } from "../params/interface";
6-
import { State } from "./stateObject";
6+
import { StateObject } from "./stateObject";
77
import { ViewContext } from "../view/interface";
88
import { IInjectable } from "../common/common";
99
import { Transition } from "../transition/transition";
@@ -12,10 +12,10 @@ import { ResolvePolicy, ResolvableLiteral, ProviderLike } from "../resolve/inter
1212
import { Resolvable } from "../resolve/resolvable";
1313
import { TargetState } from "./targetState";
1414

15-
export type StateOrName = (string|StateDeclaration|State);
15+
export type StateOrName = (string|StateDeclaration|StateObject);
1616

1717
/** @internalapi */
18-
export interface TransitionPromise extends Promise<State> {
18+
export interface TransitionPromise extends Promise<StateObject> {
1919
transition: Transition;
2020
}
2121

@@ -163,7 +163,7 @@ export interface StateDeclaration {
163163
*
164164
* Note: the internal [[State]] API is subject to change without notice
165165
*/
166-
$$state?: () => State;
166+
$$state?: () => StateObject;
167167

168168
/**
169169
* Resolve - a mechanism to asynchronously fetch data, participating in the Transition lifecycle

0 commit comments

Comments
 (0)