Skip to content

Commit

Permalink
feat(StateObject): Rename internal State object to StateObject
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
christopherthielen committed Feb 23, 2017
1 parent 642df0b commit feceaf9
Show file tree
Hide file tree
Showing 30 changed files with 124 additions and 124 deletions.
6 changes: 3 additions & 3 deletions src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { isFunction, isString, isArray, isRegExp, isDate, isDefined } from "./predicates";
import { all, any, prop, curry, val, not } from "./hof";
import { services } from "./coreservices";
import { State } from "../state/stateObject";
import { StateObject } from "../state/stateObject";

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

for (var n in first.path) {
if (first.path[n] !== second.path[n]) break;
Expand Down
4 changes: 2 additions & 2 deletions src/common/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/** */
import { and, not, pipe, prop, or } from "./hof";
import { Predicate } from "./common"; // has or is using
import { State } from "../state/stateObject";
import { StateObject } from "../state/stateObject";

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

/**
* Predicate which checks if a value is injectable
Expand Down
4 changes: 2 additions & 2 deletions src/common/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {PathNode} from "../path/node";
import {PolicyWhen} from "../resolve/interface";
import {TransitionHook} from "../transition/transitionHook";
import {HookResult} from "../transition/interface";
import {State} from "../state/stateObject";
import {StateObject} from "../state/stateObject";

/** @hidden */
function uiViewString (viewData: ActiveUIView) {
Expand Down Expand Up @@ -193,7 +193,7 @@ export class Trace {
}

/** @internalapi called by ui-router code */
traceSuccess(finalState: State, trans: Transition) {
traceSuccess(finalState: StateObject, trans: Transition) {
if (!this.enabled(Category.TRANSITION)) return;
console.log(`${transLbl(trans)}: <- Success ${stringify(trans)}, final state: ${finalState.name}`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/ /** */
import {StateParams} from "./params/stateParams";
import {StateDeclaration} from "./state/interface";
import {State} from "./state/stateObject";
import {StateObject} from "./state/stateObject";
import {Transition} from "./transition/transition";
import {Queue} from "./common/queue";
import {TransitionService} from "./transition/transitionService";
Expand Down Expand Up @@ -38,7 +38,7 @@ export class UIRouterGlobals implements Disposable {
* The to-state from the latest successful transition
* @internalapi
*/
$current: State;
$current: StateObject;

/**
* The current transition (in progress)
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/onEnterExitRetain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @module hooks */ /** for typedoc */
import {TransitionStateHookFn} from "../transition/interface";
import {State} from "../state/stateObject";
import {StateObject} from "../state/stateObject";
import {Transition} from "../transition/transition";
import {TransitionService} from "../transition/transitionService";

Expand All @@ -13,7 +13,7 @@ import {TransitionService} from "../transition/transitionService";
* @hidden
*/
function makeEnterExitRetainHook(hookName: string): TransitionStateHookFn {
return (transition: Transition, state: State) => {
return (transition: Transition, state: StateObject) => {
let hookFn: TransitionStateHookFn = state[hookName];
return hookFn(transition, state);
}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @module hooks */ /** for typedoc */
import {noop} from "../common/common";
import {Transition} from "../transition/transition";
import {State} from "../state/stateObject";
import {StateObject} from "../state/stateObject";
import {ResolveContext} from "../resolve/resolveContext";
import {TransitionStateHookFn, TransitionHookFn} from "../transition/interface";
import {TransitionService} from "../transition/transitionService";
Expand Down Expand Up @@ -33,7 +33,7 @@ export const registerEagerResolvePath = (transitionService: TransitionService) =
*
* See [[StateDeclaration.resolve]]
*/
const lazyResolveState: TransitionStateHookFn = (trans: Transition, state: State) =>
const lazyResolveState: TransitionStateHookFn = (trans: Transition, state: StateObject) =>
new ResolveContext(trans.treeChanges().to)
.subContext(state)
.resolvePath("LAZY", trans)
Expand Down
4 changes: 2 additions & 2 deletions src/params/stateParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
/** */
import {extend, ancestors, Obj} from "../common/common";
import {State} from "../state/stateObject";
import {StateObject} from "../state/stateObject";

/** @internalapi */
export class StateParams {
Expand All @@ -22,7 +22,7 @@ export class StateParams {
* @param {Object} $current Internal definition of object representing the current state.
* @param {Object} $to Internal definition of object representing state to transition to.
*/
$inherit(newParams: Obj, $current: State, $to: State) {
$inherit(newParams: Obj, $current: StateObject, $to: StateObject) {
let parents = ancestors($current, $to),
parentParams: string[],
inherited: Obj = {},
Expand Down
8 changes: 4 additions & 4 deletions src/path/node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @module path */ /** for typedoc */
import {extend, applyPairs, find, allTrueR} from "../common/common";
import {propEq} from "../common/hof";
import {State} from "../state/stateObject";
import {StateObject} from "../state/stateObject";
import {RawParams} from "../params/interface";
import {Param} from "../params/param";
import {Resolvable} from "../resolve/resolvable";
Expand All @@ -16,7 +16,7 @@ import {ViewConfig} from "../view/interface";
*/
export class PathNode {
/** The state being entered, exited, or retained */
public state: State;
public state: StateObject;
/** The parameters declared on the state */
public paramSchema: Param[];
/** The parameter values that belong to the state */
Expand All @@ -29,7 +29,7 @@ export class PathNode {
/** Creates a copy of a PathNode */
constructor(state: PathNode);
/** Creates a new (empty) PathNode for a State */
constructor(state: State);
constructor(state: StateObject);
constructor(stateOrPath: any) {
if (stateOrPath instanceof PathNode) {
let node: PathNode = stateOrPath;
Expand All @@ -39,7 +39,7 @@ export class PathNode {
this.resolvables = node.resolvables.slice();
this.views = node.views && node.views.slice();
} else {
let state: State = stateOrPath;
let state: StateObject = stateOrPath;
this.state = state;
this.paramSchema = state.parameters({ inherit: false });
this.paramValues = {};
Expand Down
10 changes: 5 additions & 5 deletions src/path/pathFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {TreeChanges} from "../transition/interface";
import {ViewConfig} from "../view/interface";
import {_ViewDeclaration} from "../state/interface";

import {State} from "../state/stateObject";
import {StateObject} from "../state/stateObject";
import {TargetState} from "../state/targetState";
import {PathNode} from "../path/node";
import {ViewService} from "../view/view";
Expand Down Expand Up @@ -45,7 +45,7 @@ export class PathFactory {
*
* On each [[PathNode]], creates ViewConfig objects from the views: property of the node's state
*/
static applyViewConfigs($view: ViewService, path: PathNode[], states: State[]) {
static applyViewConfigs($view: ViewService, path: PathNode[], states: StateObject[]) {
// Only apply the viewConfigs to the nodes for the given states
path.filter(node => inArray(states, node.state)).forEach(node => {
let viewDecls: _ViewDeclaration[] = values(node.state.views || {});
Expand All @@ -67,7 +67,7 @@ export class PathFactory {
* it is not inherited from the fromPath.
*/
static inheritParams(fromPath: PathNode[], toPath: PathNode[], toKeys: string[] = []): PathNode[] {
function nodeParamVals(path: PathNode[], state: State): RawParams {
function nodeParamVals(path: PathNode[], state: StateObject): RawParams {
let node: PathNode = find(path, propEq('state', state));
return extend({}, node && node.paramValues);
}
Expand Down Expand Up @@ -100,9 +100,9 @@ export class PathFactory {
/**
* Computes the tree changes (entering, exiting) between a fromPath and toPath.
*/
static treeChanges(fromPath: PathNode[], toPath: PathNode[], reloadState: State): TreeChanges {
static treeChanges(fromPath: PathNode[], toPath: PathNode[], reloadState: StateObject): TreeChanges {
let keep = 0, max = Math.min(fromPath.length, toPath.length);
const staticParams = (state: State) =>
const staticParams = (state: StateObject) =>
state.parameters({ inherit: false }).filter(not(prop('dynamic'))).map(prop('id'));
const nodesMatch = (node1: PathNode, node2: PathNode) =>
node1.equals(node2, staticParams(node1.state));
Expand Down
6 changes: 3 additions & 3 deletions src/resolve/resolvable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {ResolveContext} from "./resolveContext";
import {stringify} from "../common/strings";
import {isFunction, isObject} from "../common/predicates";
import {Transition} from "../transition/transition";
import {State} from "../state/stateObject";
import {StateObject} from "../state/stateObject";
import {PathNode} from "../path/node";


Expand Down Expand Up @@ -90,7 +90,7 @@ export class Resolvable implements ResolvableLiteral {
}
}

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

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

// After the final value has been resolved, update the state of the Resolvable
Expand Down
6 changes: 3 additions & 3 deletions src/resolve/resolveContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { services, $InjectorLike } from "../common/coreservices";
import { resolvePolicies, PolicyWhen, ResolvePolicy } from "./interface";
import { PathNode } from "../path/node";
import { Resolvable } from "./resolvable";
import { State } from "../state/stateObject";
import { StateObject } from "../state/stateObject";
import { PathFactory } from "../path/pathFactory";
import { stringify } from "../common/strings";
import { Transition } from "../transition/transition";
Expand Down Expand Up @@ -81,7 +81,7 @@ export class ResolveContext {
* When resolving for the `B` node, first take the full "To Path" Context `[A,B,C,D]` and limit to the subpath `[A,B]`.
* `let AB = ABCD.subcontext(a)`
*/
subContext(state: State): ResolveContext {
subContext(state: StateObject): ResolveContext {
return new ResolveContext(PathFactory.subPath(this._path, node => node.state === state));
}

Expand All @@ -100,7 +100,7 @@ export class ResolveContext {
* @param newResolvables the new Resolvables
* @param state Used to find the node to put the resolvable on
*/
addResolvables(newResolvables: Resolvable[], state: State) {
addResolvables(newResolvables: Resolvable[], state: StateObject) {
let node = <PathNode> find(this._path, propEq('state', state));
let keys = newResolvables.map(r => r.token);
node.resolvables = node.resolvables.filter(r => keys.indexOf(r.token) === -1).concat(newResolvables);
Expand Down
8 changes: 4 additions & 4 deletions src/state/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module state
*/ /** for typedoc */
import { ParamDeclaration, RawParams, ParamsOrArray } from "../params/interface";
import { State } from "./stateObject";
import { StateObject } from "./stateObject";
import { ViewContext } from "../view/interface";
import { IInjectable } from "../common/common";
import { Transition } from "../transition/transition";
Expand All @@ -12,10 +12,10 @@ import { ResolvePolicy, ResolvableLiteral, ProviderLike } from "../resolve/inter
import { Resolvable } from "../resolve/resolvable";
import { TargetState } from "./targetState";

export type StateOrName = (string|StateDeclaration|State);
export type StateOrName = (string|StateDeclaration|StateObject);

/** @internalapi */
export interface TransitionPromise extends Promise<State> {
export interface TransitionPromise extends Promise<StateObject> {
transition: Transition;
}

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

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

0 comments on commit feceaf9

Please sign in to comment.