Skip to content

Commit a92d284

Browse files
refactor(StateObject): rename State object refs to StateObject
1 parent 21eced9 commit a92d284

File tree

6 files changed

+19
-21
lines changed

6 files changed

+19
-21
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"jsnext:main": "lib-esm/index.js",
6464
"typings": "lib/index.d.ts",
6565
"dependencies": {
66-
"ui-router-core": "3.1.0"
66+
"ui-router-core": "^5.0.0"
6767
},
6868
"peerDependencies": {
6969
"angular": ">=1.2.0"

src/legacy/resolveService.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @module ng1 */ /** */
2-
import { State, PathNode, ResolveContext, Obj, mapObj, resolvablesBuilder } from "ui-router-core";
2+
import { StateObject, PathNode, ResolveContext, Obj, mapObj, resolvablesBuilder } from "ui-router-core";
33
import * as angular from "angular";
44

55
/**
@@ -43,8 +43,8 @@ var $resolve = {
4343
* @param parent a promise for a "parent resolve"
4444
*/
4545
resolve: (invocables: { [key: string]: Function }, locals = {}, parent?: Promise<any>) => {
46-
let parentNode = new PathNode(new State(<any> { params: {}, resolvables: [] }));
47-
let node = new PathNode(new State(<any> { params: {}, resolvables: [] }));
46+
let parentNode = new PathNode(new StateObject(<any> { params: {}, resolvables: [] }));
47+
let node = new PathNode(new StateObject(<any> { params: {}, resolvables: [] }));
4848
let context = new ResolveContext([parentNode, node]);
4949

5050
context.addResolvables(resolvablesBuilder(<any> { resolve: invocables }), node.state);

src/statebuilders/onEnterExitRetain.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/** @module ng1 */ /** */
22
import {
3-
State, TransitionStateHookFn, HookResult, Transition, services, ResolveContext, extend, BuilderFunction
3+
StateObject, TransitionStateHookFn, HookResult, Transition, services, ResolveContext, extend, BuilderFunction
44
} from "ui-router-core";
55
import { getLocals } from "../services";
6+
import { Ng1StateDeclaration } from '../interface';
67

78
/**
89
* This is a [[StateBuilder.builder]] function for angular1 `onEnter`, `onExit`,
@@ -12,11 +13,11 @@ import { getLocals } from "../services";
1213
* ensures that those hooks are injectable for angular-ui-router (ng1).
1314
*/
1415
export const getStateHookBuilder = (hookName: "onEnter"|"onExit"|"onRetain") =>
15-
function stateHookBuilder(state: State, parentFn: BuilderFunction): TransitionStateHookFn {
16+
function stateHookBuilder(state: StateObject, parentFn: BuilderFunction): TransitionStateHookFn {
1617
let hook = state[hookName];
1718
let pathname = hookName === 'onExit' ? 'from' : 'to';
1819

19-
function decoratedNg1Hook(trans: Transition, state: State): HookResult {
20+
function decoratedNg1Hook(trans: Transition, state: Ng1StateDeclaration): HookResult {
2021
let resolveContext = new ResolveContext(trans.treeChanges(pathname));
2122
let locals = extend(getLocals(resolveContext), { $state$: state, $transition$: trans });
2223
return services.$injector.invoke(hook, this, locals);

src/statebuilders/views.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/** @module ng1 */ /** */
22
import { ng as angular } from "../angular";
33
import {
4-
State, pick, forEach, anyTrueR, tail, extend,
4+
StateObject, pick, forEach, tail, extend,
55
isArray, isInjectable, isDefined, isString, services, trace,
6-
ViewConfig, ViewService, ViewConfigFactory, PathNode, ResolveContext, Resolvable, RawParams, IInjectable
6+
ViewConfig, ViewService, ViewConfigFactory, PathNode, ResolveContext, Resolvable, IInjectable
77
} from "ui-router-core";
88
import { Ng1ViewDeclaration } from "../interface";
99
import { TemplateFactory } from "../templateFactory";
@@ -29,7 +29,7 @@ const hasAnyKey = (keys, obj) =>
2929
* If no `views: {}` property exists on the [[StateDeclaration]], then it creates the `views` object
3030
* and applies the state-level configuration to a view named `$default`.
3131
*/
32-
export function ng1ViewsBuilder(state: State) {
32+
export function ng1ViewsBuilder(state: StateObject) {
3333
// Do not process root state
3434
if (!state.parent) return {};
3535

test/resolveSpec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ declare var inject;
66
import Spy = jasmine.Spy;
77
import "./util/matchers";
88
import { resolvedValue, resolvedError, caught } from './util/testUtilsNg1';
9-
import { ResolveContext, State, PathNode, omit, pick, inherit, forEach } from "ui-router-core";
9+
import { ResolveContext, StateObject, PathNode, omit, pick, inherit, forEach } from "ui-router-core";
1010
import { UIRouter, Resolvable, services, StateDeclaration } from "ui-router-core";
1111
import "../src/legacy/resolveService";
1212

1313
let module = angular['mock'].module;
1414
///////////////////////////////////////////////
1515

16-
var states, statesTree, statesMap: { [key:string]: State } = {};
16+
var states, statesTree, statesMap: { [key:string]: StateObject } = {};
1717
var emptyPath;
1818
var vals, counts, expectCounts;
1919
var asyncCount;
@@ -75,7 +75,7 @@ beforeEach(function () {
7575
angular.forEach(substates, function (value, key) {
7676
thisState.data.children.push(loadStates(thisState, value, key));
7777
});
78-
thisState = angular.extend(new State(thisState), { self: thisState });
78+
thisState = StateObject.create(thisState);
7979
statesMap[name] = thisState;
8080
return thisState;
8181
}
@@ -444,7 +444,7 @@ describe("Integration: Resolvables system", () => {
444444
copy[name] = stateDef;
445445
});
446446

447-
angular.forEach(copy, (stateDef: State) => {
447+
angular.forEach(copy, (stateDef: StateObject) => {
448448
if (stateDef.name) $stateProvider.state(stateDef.self);
449449
});
450450
}));

test/viewSpec.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as angular from "angular";
22
import "./util/matchers";
33
import {
4-
inherit, extend, tail, curry, PathNode, PathFactory, ViewService, StateMatcher, StateBuilder, State
4+
inherit, extend, tail, curry, PathNode, PathFactory, ViewService, StateMatcher, StateBuilder, StateObject
55
} from "ui-router-core";
66
import { ng1ViewsBuilder, getNg1ViewConfigFactory } from "../src/statebuilders/views";
77
import { Ng1StateDeclaration } from "../src/interface";
88
declare var inject;
99

1010
describe('view', function() {
1111
var scope, $compile, $injector, elem, $controllerProvider, $urlMatcherFactoryProvider;
12-
let root: State, states: {[key: string]: State};
12+
let root: StateObject, states: {[key: string]: StateObject};
1313

1414
beforeEach(angular['mock'].module('ui.router', function(_$provide_, _$controllerProvider_, _$urlMatcherFactoryProvider_) {
1515
_$provide_.factory('foo', function() {
@@ -21,11 +21,8 @@ describe('view', function() {
2121

2222
let register;
2323
let registerState = curry(function(_states, stateBuilder, config) {
24-
let state = inherit(new State(), extend({}, config, {
25-
self: config,
26-
resolve: config.resolve || []
27-
}));
28-
let built: State = stateBuilder.build(state);
24+
let state = StateObject.create(config);
25+
let built: StateObject = stateBuilder.build(state);
2926
return _states[built.name] = built;
3027
});
3128

0 commit comments

Comments
 (0)