From 2b0e48b61f85641d9be2806cbe63f03e5b6081e8 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Sat, 18 Feb 2017 10:29:27 -0800 Subject: [PATCH] fix(TransitionHook): Transition hooks no longer expose the internal StateObject BREAKING CHANGE: Transition hooks no longer expose the internal `State` object (now named `StateObject`) - #### Before: ```js import { State } from "ui-router-core"; const match = { to: (state: State) => state.data.auth }; transitionsvc.onEnter(match, (trans: Transition, state: State) => { // state is the internal State object if (state.includes["foo"]) { // internal ui-router API return false; } } ``` - #### Now: ```js import { StateDeclaration } from "ui-router-core"; const match = { to: (state: StateDeclaration) => state.data.auth }; transitionsvc.onEnter(match, (trans: Transition, state: StateDeclaration) => { // state === the state object you registered // Access internal ui-router API using $$state() if (state.$$state().includes["foo"]) { return false; } } ``` - #### Motivation: The `State` object (now named `StateObject`) is an internal API and should not be exposed via any public APIs. If you depend on the internal APIs, you can still access the internal object by calling `state.$$state()`. - #### BC Likelihood How likely is this BC to affect me? Medium: You will likely be affected you 1) have transition hooks, 2) are using typescript and/or 3) use the internal ui-router State API. - #### BC Severity How severe is this BC? Low: Access to the internal api is still available using `$$state()`. --- src/hooks/onEnterExitRetain.ts | 4 +- src/hooks/resolve.ts | 21 ++++--- src/transition/hookBuilder.ts | 2 +- src/transition/interface.ts | 7 ++- src/transition/transitionHook.ts | 6 +- test/stateServiceSpec.ts | 105 ++++++++++++++++--------------- test/transitionSpec.ts | 86 +++++++++++++------------ 7 files changed, 116 insertions(+), 115 deletions(-) diff --git a/src/hooks/onEnterExitRetain.ts b/src/hooks/onEnterExitRetain.ts index 5e7fa80b..dca1c0d5 100644 --- a/src/hooks/onEnterExitRetain.ts +++ b/src/hooks/onEnterExitRetain.ts @@ -1,8 +1,8 @@ /** @module hooks */ /** for typedoc */ import {TransitionStateHookFn} from "../transition/interface"; -import {StateObject} from "../state/stateObject"; import {Transition} from "../transition/transition"; import {TransitionService} from "../transition/transitionService"; +import { StateDeclaration } from '../state/interface'; /** * A factory which creates an onEnter, onExit or onRetain transition hook function @@ -13,7 +13,7 @@ import {TransitionService} from "../transition/transitionService"; * @hidden */ function makeEnterExitRetainHook(hookName: string): TransitionStateHookFn { - return (transition: Transition, state: StateObject) => { + return (transition: Transition, state: StateDeclaration) => { let hookFn: TransitionStateHookFn = state[hookName]; return hookFn(transition, state); } diff --git a/src/hooks/resolve.ts b/src/hooks/resolve.ts index 08cc9cdb..25d70cb0 100644 --- a/src/hooks/resolve.ts +++ b/src/hooks/resolve.ts @@ -1,11 +1,12 @@ -/** @module hooks */ /** for typedoc */ -import {noop} from "../common/common"; -import {Transition} from "../transition/transition"; -import {StateObject} from "../state/stateObject"; -import {ResolveContext} from "../resolve/resolveContext"; -import {TransitionStateHookFn, TransitionHookFn} from "../transition/interface"; -import {TransitionService} from "../transition/transitionService"; -import {val} from "../common/hof"; +/** @module hooks */ +/** for typedoc */ +import { noop } from '../common/common'; +import { Transition } from '../transition/transition'; +import { ResolveContext } from '../resolve/resolveContext'; +import { TransitionStateHookFn, TransitionHookFn } from '../transition/interface'; +import { TransitionService } from '../transition/transitionService'; +import { val } from '../common/hof'; +import { StateDeclaration } from '../state/interface'; /** * A [[TransitionHookFn]] which resolves all EAGER Resolvables in the To Path @@ -33,9 +34,9 @@ export const registerEagerResolvePath = (transitionService: TransitionService) = * * See [[StateDeclaration.resolve]] */ -const lazyResolveState: TransitionStateHookFn = (trans: Transition, state: StateObject) => +const lazyResolveState: TransitionStateHookFn = (trans: Transition, state: StateDeclaration) => new ResolveContext(trans.treeChanges().to) - .subContext(state) + .subContext(state.$$state()) .resolvePath("LAZY", trans) .then(noop); diff --git a/src/transition/hookBuilder.ts b/src/transition/hookBuilder.ts index 286c8a78..6a2fb722 100644 --- a/src/transition/hookBuilder.ts +++ b/src/transition/hookBuilder.ts @@ -79,7 +79,7 @@ export class HookBuilder { traceData: { hookType: hookType.name, context: node } }, baseHookOptions); - let state = hookType.criteriaMatchPath.scope === TransitionHookScope.STATE ? node.state : null; + let state = hookType.criteriaMatchPath.scope === TransitionHookScope.STATE ? node.state.self : null; let transitionHook = new TransitionHook(transition, state, hook, _options); return { hook, node, transitionHook }; }); diff --git a/src/transition/interface.ts b/src/transition/interface.ts index effe7576..ffe9cef6 100644 --- a/src/transition/interface.ts +++ b/src/transition/interface.ts @@ -210,7 +210,7 @@ export interface TransitionHookFn { * - [[IHookRegistry.onEnter]] */ export interface TransitionStateHookFn { - (transition: Transition, state: StateObject) : HookResult + (transition: Transition, state: StateDeclaration) : HookResult } /** @@ -700,8 +700,9 @@ export interface IHookRegistry { _registeredHooks: { [key: string]: RegisteredHook[] } } -/** A predicate type which takes a [[StateObject]] and returns a boolean */ -export type IStateMatch = Predicate +/** A predicate type which tests if a [[StateDeclaration]] passes some test. Returns a boolean. */ +export type IStateMatch = Predicate + /** * This object is used to configure whether or not a Transition Hook is invoked for a particular transition, * based on the Transition's "to state" and "from state". diff --git a/src/transition/transitionHook.ts b/src/transition/transitionHook.ts index ef48c5ca..5196475e 100644 --- a/src/transition/transitionHook.ts +++ b/src/transition/transitionHook.ts @@ -13,9 +13,9 @@ import { services } from '../common/coreservices'; import { Rejection } from './rejectFactory'; import { TargetState } from '../state/targetState'; import { Transition } from './transition'; -import { StateObject } from '../state/stateObject'; import { TransitionEventType } from './transitionEventType'; -import { RegisteredHook } from './hookRegistry'; // has or is using +import { RegisteredHook } from './hookRegistry'; +import { StateDeclaration } from '../state/interface'; // has or is using let defaultOptions: TransitionHookOptions = { current: noop, @@ -34,7 +34,7 @@ export type ErrorHandler = (error) => Promise; export class TransitionHook { type: TransitionEventType; constructor(private transition: Transition, - private stateContext: StateObject, + private stateContext: StateDeclaration, private registeredHook: RegisteredHook, private options: TransitionHookOptions) { this.options = defaults(options, defaultOptions); diff --git a/test/stateServiceSpec.ts b/test/stateServiceSpec.ts index de964e61..eee8c194 100644 --- a/test/stateServiceSpec.ts +++ b/test/stateServiceSpec.ts @@ -1,15 +1,15 @@ -import { UIRouter, TransitionService, StateService } from "../src/index"; -import { tree2Array, awaitTransition } from "./_testUtils"; -import "./_matchers"; -import { TransitionOptions } from "../src/transition/interface"; -import { LocationServices, services } from "../src/common/coreservices"; -import { isFunction } from "../src/common/predicates"; -import { StateRegistry } from "../src/state/stateRegistry"; -import { StateObject } from "../src/state/stateObject"; -import { Transition } from "../src/transition/transition"; -import { Param } from "../src/params/param"; -import { RejectType } from "../src/transition/rejectFactory"; -import { TestingPlugin } from "./_testingPlugin"; +import { UIRouter, TransitionService, StateService } from '../src/index'; +import { tree2Array, awaitTransition } from './_testUtils'; +import './_matchers'; +import { TransitionOptions } from '../src/transition/interface'; +import { LocationServices } from '../src/common/coreservices'; +import { isFunction } from '../src/common/predicates'; +import { StateRegistry } from '../src/state/stateRegistry'; +import { Transition } from '../src/transition/transition'; +import { Param } from '../src/params/param'; +import { RejectType } from '../src/transition/rejectFactory'; +import { TestingPlugin } from './_testingPlugin'; +import { StateDeclaration } from '../src/state/interface'; describe('stateService', function () { let router: UIRouter; @@ -44,7 +44,7 @@ describe('stateService', function () { describe('transitionTo', () => { beforeEach(() => { - var stateTree = { + let stateTree = { first: {}, second: {}, third: {}, @@ -73,8 +73,8 @@ describe('stateService', function () { }); $transitions.onStart({ to: 'C'}, trans => { cOpts = trans.options(); }); - var log = [], promise = $state.go("D"); - var cOpts: TransitionOptions = {}; + let log = [], promise = $state.go("D"); + let cOpts: TransitionOptions = {}; promise.then(() => { expect(log).toEqual(['redirect']); @@ -119,7 +119,7 @@ describe('stateService', function () { it("should not update the URL in response to synchronizing URL", ((done) => { $loc.url('/a/b/c'); - var url = spyOn($loc, 'url').and.callThrough(); + let url = spyOn($loc, 'url').and.callThrough(); wait().then(() => { expect($state.current.name).toBe('C'); @@ -134,7 +134,7 @@ describe('stateService', function () { $transitions.onStart({ to: 'C' }, () => $state.target('D')); $loc.url('/a/b/c'); - var url = spyOn($loc, 'url').and.callThrough(); + let url = spyOn($loc, 'url').and.callThrough(); wait().then(() => { expect($state.current.name).toBe('D'); @@ -147,7 +147,7 @@ describe('stateService', function () { }); describe('.transitionTo()', function () { - var A, B, C, D, DD; + let A, B, C, D, DD; beforeEach(() => { A = { name: 'A', url: '/a' }; B = { name: 'B', url: '/b' }; @@ -175,8 +175,8 @@ describe('stateService', function () { }); describe("dynamic transitions", function () { - var dynlog, paramsChangedLog; - var dynamicstate, childWithParam, childNoParam; + let dynlog, paramsChangedLog; + let dynamicstate, childWithParam, childNoParam; beforeEach(async function (done) { $loc.url("asdfasfdasf"); @@ -209,9 +209,10 @@ describe('stateService', function () { router.stateRegistry.register(childNoParam); function logChangedParams(prefix, suffix) { - return (trans: Transition, state: StateObject) => { + return (trans: Transition, state: StateDeclaration) => { trans.onSuccess({}, () => { - let changed = Param.changed(state.parameters({ inherit: true }), trans.params("to"), trans.params("from")) + let stateObject = state.$$state(); + let changed = Param.changed(stateObject.parameters({ inherit: true }), trans.params("to"), trans.params("from")) .map(param => param.id + "=" + trans.params("to")[param.id]) .join(","); if (changed) { @@ -249,39 +250,39 @@ describe('stateService', function () { describe('[ transition.dynamic() ]:', function() { it('is considered fully dynamic when only dynamic params have changed', () => { - var promise = $state.go(".", {pathDyn: "pd2", searchDyn: 'sd2'}); + let promise = $state.go(".", {pathDyn: "pd2", searchDyn: 'sd2'}); expect(promise.transition.dynamic()).toBeTruthy(); }); it('is not considered fully dynamic if any state is entered', function () { - var promise = $state.go(childWithParam); + let promise = $state.go(childWithParam); expect(promise.transition.dynamic()).toBeFalsy(); }); it('is not considered fully dynamic if any state is exited', async function (done) { await initStateTo(childWithParam, { config: 'p1', path: 'p1', pathDyn: 'pd1', search: 's1', searchDyn: 'sd1' }); - var promise = $state.go(dynamicstate); + let promise = $state.go(dynamicstate); expect(promise.transition.dynamic()).toBeFalsy(); done(); }); it('is not considered fully dynamic if any state is reloaded', function () { - var promise = $state.go(dynamicstate, null, { reload: true }); + let promise = $state.go(dynamicstate, null, { reload: true }); expect(promise.transition.dynamic()).toBeFalsy(); }); it('is not considered fully dynamic if any non-dynamic parameter changes', function () { - var promise = $state.go(dynamicstate, { path: 'p2' }); + let promise = $state.go(dynamicstate, { path: 'p2' }); expect(promise.transition.dynamic()).toBeFalsy(); }); }); describe('[ promises ]', function() { it('runs successful transition when fully dynamic', async (done) => { - var promise = $state.go(dynamicstate, {searchDyn: 'sd2'}); - var transition = promise.transition; - var transSuccess = false; + let promise = $state.go(dynamicstate, {searchDyn: 'sd2'}); + let transition = promise.transition; + let transSuccess = false; transition.promise.then(function(result) { transSuccess = true; }); await promise; @@ -295,8 +296,8 @@ describe('stateService', function () { it('resolves the $state.go() promise with the original/final state, when fully dynamic', async (done) => { await initStateTo(dynamicstate, { path: 'p1', pathDyn: 'pd1', search: 's1', searchDyn: 'sd1' }); - var promise = $state.go(dynamicstate, { pathDyn: 'pd2', searchDyn: 'sd2' }); - var destState = await promise; + let promise = $state.go(dynamicstate, { pathDyn: 'pd2', searchDyn: 'sd2' }); + let destState = await promise; expect(promise.transition.dynamic()).toBeTruthy(); expect($state.current).toBe(dynamicstate); @@ -308,7 +309,7 @@ describe('stateService', function () { describe('[ enter/exit ]', function() { it('does not exit nor enter any states when fully dynamic', async (done) => { - var promise = $state.go(dynamicstate, { searchDyn: 'sd2' }); + let promise = $state.go(dynamicstate, { searchDyn: 'sd2' }); await promise; expect(promise.transition.dynamic()).toBeTruthy(); @@ -322,7 +323,7 @@ describe('stateService', function () { }); it('does not exit nor enter the state when only dynamic search params change', async (done) => { - var promise = $state.go(dynamicstate, {searchDyn: 'sd2'}); + let promise = $state.go(dynamicstate, {searchDyn: 'sd2'}); await promise; expect(promise.transition.dynamic()).toBeTruthy(); @@ -333,7 +334,7 @@ describe('stateService', function () { }); it('does not exit nor enter the state when only dynamic path params change', async (done) => { - var promise = $state.go(dynamicstate, {pathDyn: 'pd2'}); + let promise = $state.go(dynamicstate, {pathDyn: 'pd2'}); await promise; expect(promise.transition.dynamic()).toBeTruthy(); @@ -344,7 +345,7 @@ describe('stateService', function () { }); it('exits and enters a state when a non-dynamic search param changes', async (done) => { - var promise = $state.go(dynamicstate, {search: 's2'}); + let promise = $state.go(dynamicstate, {search: 's2'}); await promise; expect(promise.transition.dynamic()).toBeFalsy(); @@ -355,7 +356,7 @@ describe('stateService', function () { }); it('exits and enters a state when a non-dynamic path param changes', async (done) => { - var promise = $state.go(dynamicstate, {path: 'p2'}); + let promise = $state.go(dynamicstate, {path: 'p2'}); await promise; expect(promise.transition.dynamic()).toBeFalsy(); @@ -430,7 +431,7 @@ describe('stateService', function () { }); describe("(with dynamic params because reloadOnSearch=false)", function () { - var RS; + let RS; beforeEach((done) => { RS = { name: 'RS', url: '^/search?term', reloadOnSearch: false }; @@ -440,7 +441,7 @@ describe('stateService', function () { describe("and only query params changed", function () { - var entered = false; + let entered = false; beforeEach(() => { $transitions.onEnter({entering: 'RS'}, function () { entered = true }); }); @@ -455,8 +456,8 @@ describe('stateService', function () { }); it('doesn\'t re-enter state (triggered by $state transition)', async (done) => { - var promise = $state.go($state.current, {term: "hello"}); - var success = false, transition = promise.transition; + let promise = $state.go($state.current, {term: "hello"}); + let success = false, transition = promise.transition; transition.promise.then(function () { success = true; }); await promise; @@ -505,7 +506,7 @@ describe('stateService', function () { await initStateTo(A); expect(enterlog).toBe('A;'); - var promise = $state.transitionTo(A, {}); // no-op + let promise = $state.transitionTo(A, {}); // no-op expect(promise).toBeDefined(); // but we still get a valid promise let value = await promise; @@ -520,10 +521,10 @@ describe('stateService', function () { $state.defaultErrorHandler(() => null); await initStateTo(A); - var superseded = $state.transitionTo(B, {}).catch(err => err); + let superseded = $state.transitionTo(B, {}).catch(err => err); await $state.transitionTo(C, {}); - var result = await superseded; + let result = await superseded; expect($state.current).toBe(C); expect(result).toBeTruthy(); @@ -534,9 +535,9 @@ describe('stateService', function () { $state.defaultErrorHandler(() => null); await initStateTo(A); - var superseded = $state.transitionTo(B, {}).catch(err => err); + let superseded = $state.transitionTo(B, {}).catch(err => err); await $state.transitionTo(A, {}); - var result = await superseded; + let result = await superseded; expect($state.current).toBe(A); expect(result.type).toBe(RejectType.SUPERSEDED); @@ -561,7 +562,7 @@ describe('stateService', function () { }); it('triggers onEnter and onExit callbacks', async(done) => { - var log = ""; + let log = ""; await initStateTo(A); $transitions.onSuccess({}, (trans) => { log += trans.to().name + ";" }); $transitions.onEnter({}, (trans, state) => { log += state.name + ".onEnter;" }); @@ -594,7 +595,7 @@ describe('stateService', function () { onExit: function (trans, state) { expect(trans.from().name).toBe('design'); expect(trans.to().name).toBe('A'); - expect(state.self).toBe($registry.get('design')); + expect(state).toBe($registry.get('design')); expect(trans.injector(null, 'from').get('cc')).toBe('cc resolve'); } }); @@ -617,8 +618,8 @@ describe('stateService', function () { it('notifies on failed relative state resolution', async (done) => { await $state.transitionTo(DD); - var actual: any; - var message = "Could not resolve '^.Z' from state 'DD'"; + let actual: any; + let message = "Could not resolve '^.Z' from state 'DD'"; await $state.transitionTo("^.Z", null, { relative: $state.$current }).catch(function (err) { actual = err; }); @@ -637,7 +638,7 @@ describe('stateService', function () { }); it('runs a transition when the location #fragment is updated', async(done) => { - var transitionCount = 0; + let transitionCount = 0; $transitions.onSuccess({}, () => { transitionCount++; }); await $state.transitionTo('A', { '#': 'frag' }); @@ -652,7 +653,7 @@ describe('stateService', function () { }); it('injects $transition$ into resolves', async(done) => { - var log = ""; + let log = ""; $registry.register({ name: 'about', url: "/about", diff --git a/test/transitionSpec.ts b/test/transitionSpec.ts index 8e8fff0c..49d5f16e 100644 --- a/test/transitionSpec.ts +++ b/test/transitionSpec.ts @@ -39,7 +39,7 @@ describe('transition', function () { $state = router.stateService; $transitions = router.transitionService; - var stateTree = { + let stateTree = { first: {}, second: {}, third: {}, @@ -67,7 +67,7 @@ describe('transition', function () { describe('service', () => { describe('async event hooks:', () => { it('$transition$.promise should resolve on success', (done) => { - var result = new PromiseResult(); + let result = new PromiseResult(); $transitions.onStart({ from: "*", to: "second" }, function($transition$) { result.setPromise($transition$.promise); }); @@ -79,7 +79,7 @@ describe('transition', function () { }); it('$transition$.promise should reject on error', (done) => { - var result = new PromiseResult(); + let result = new PromiseResult(); $transitions.onStart({ from: "*", to: "third" }, function($transition$) { result.setPromise($transition$.promise); @@ -98,7 +98,7 @@ describe('transition', function () { }); it('$transition$.promise should reject on error in synchronous hooks', ((done) => { - var result = new PromiseResult(); + let result = new PromiseResult(); $transitions.onBefore({ from: "*", to: "third" }, function($transition$) { result.setPromise($transition$.promise); @@ -117,13 +117,13 @@ describe('transition', function () { })); it('should receive the transition as the first parameter', ((done) => { - var t = null; + let t = null; $transitions.onStart({ from: "*", to: "second" }, function(trans) { t = trans; }); - var tsecond = makeTransition("", "second"); + let tsecond = makeTransition("", "second"); tsecond.run() .then(tick) .then(() => expect(t).toBe(tsecond)) @@ -164,7 +164,7 @@ describe('transition', function () { $transitions.onCreate({}, t => log += `${t.from().name};${t.to().name};`); log += "create;"; - let trans = makeTransition('first', 'second'); + makeTransition('first', 'second'); log += "created;"; expect(log).toBe('create;first;second;created;'); @@ -177,14 +177,13 @@ describe('transition', function () { $transitions.onCreate({}, t => (log += "1;", null), { priority: 1 }); log += "create;"; - let trans = makeTransition('first', 'second'); + makeTransition('first', 'second'); log += "created;"; expect(log).toBe('create;3;2;1;created;'); })); it('should ignore return values', ((done) => { - let log = ""; $transitions.onCreate({}, t => false); $transitions.onCreate({}, t => new Promise(resolve => resolve(false))); @@ -196,7 +195,6 @@ describe('transition', function () { })); it('should fail on error', () => { - let log = ""; $transitions.onCreate({}, () => { throw "doh" }); expect(() => makeTransition('first', 'second')).toThrow(); }); @@ -259,7 +257,7 @@ describe('transition', function () { describe('.onStart()', function() { it('should fire matching events when transition starts', ((done) => { - var t = null; + let t = null; $transitions.onStart({ from: "first", to: "second" }, function($transition$) { t = $transition$; }); @@ -273,14 +271,14 @@ describe('transition', function () { })); it('should get Transition as an argument, and a null state', ((done) => { - var args = { trans: undefined, state: undefined }; + let args = { trans: undefined, state: undefined }; $transitions.onStart({ from: "*", to: "third" }, function(trans, state) { args.trans = trans; args.state = state; }); - var transition = makeTransition("", "third"); - var result = new PromiseResult(transition.promise); + let transition = makeTransition("", "third"); + let result = new PromiseResult(transition.promise); transition.run() .then(tick) .then(() => { @@ -294,8 +292,8 @@ describe('transition', function () { describe('.onEnter()', function() { it('should get Transition and the state being entered as arguments', ((done) => { - var states = []; - var args = { trans: undefined, state: undefined, third: undefined }; + let states = []; + let args = { trans: undefined, state: undefined, third: undefined }; $transitions.onEnter({ entering: "*" }, function(trans, state, third) { states.push(state); @@ -316,7 +314,7 @@ describe('transition', function () { it('should be called on only states being entered', ((done) => { $transitions.onEnter({ entering: "**" }, function(trans, state) { states.push(state); }); - var states = []; + let states = []; Promise.resolve() .then(go("B", "D")) .then(() => expect(pluck(states, 'name')).toEqual([ 'C', 'D' ])) @@ -330,7 +328,7 @@ describe('transition', function () { $transitions.onEnter({ from: "*", entering: "C" }, function(trans, state) { states.push(state); }); $transitions.onEnter({ from: "B", entering: "C" }, function(trans, state) { states2.push(state); }); - var states = [], states2 = []; + let states = [], states2 = []; Promise.resolve() .then(go("A", "D")) .then(() => { @@ -351,7 +349,7 @@ describe('transition', function () { describe('.onExit()', function() { it('should get Transition, the state being exited, and Injector as arguments', ((done) => { - var args = { trans: undefined, state: undefined, third: undefined }; + let args = { trans: undefined, state: undefined, third: undefined }; $transitions.onExit({ exiting: "**" }, function(trans, state, third) { states.push(state); @@ -359,7 +357,7 @@ describe('transition', function () { args.third = third; }); - var states = []; + let states = []; Promise.resolve() .then(go("D", "H")) .then(() => { @@ -374,7 +372,7 @@ describe('transition', function () { it('should be called on only states being exited', ((done) => { $transitions.onExit({ exiting: "*" }, function(trans, state) { states.push(state); }); - var states = []; + let states = []; Promise.resolve() .then(go("D", "B")) .then(() => expect(pluck(states, 'name')).toEqual([ 'D', 'C' ])) @@ -388,7 +386,7 @@ describe('transition', function () { $transitions.onExit({ exiting: "D", to: "*" }, function(trans, state) { states.push(state); }); $transitions.onExit({ exiting: "D", to: "C" }, function(trans, state) { states2.push(state); }); - var states = [], states2 = []; + let states = [], states2 = []; Promise.resolve() .then(go("D", "B")) .then(() => { @@ -411,7 +409,7 @@ describe('transition', function () { url: '/design', resolve: { cc: () => 'cc resolve' }, onExit: (trans, state) => { - expect(state.self).toBe(router.stateRegistry.get('design')); + expect(state).toBe(router.stateRegistry.get('design')); expect(trans.injector(null, 'from').get('cc')).toBe('cc resolve'); done(); } @@ -431,7 +429,7 @@ describe('transition', function () { $transitions.onSuccess({ from: "*", to: "*" }, function(trans) { states.push(trans.to().name); }); $transitions.onEnter({ from: "A", entering: "C" }, function() { return false; }); - var states = []; + let states = []; Promise.resolve() .then(goFail("A", "C")) .then(() => expect(states).toEqual([ ])) @@ -447,7 +445,7 @@ describe('transition', function () { $transitions.onSuccess({ from: "*", to: "*" }, function() { throw new Error("oops!"); }); $transitions.onSuccess({ from: "*", to: "*" }, function(trans) { states.push(trans.to().name); }); - var states = []; + let states = []; Promise.resolve() .then(go("B", "C")) .then(() => expect(states).toEqual([ 'C' ])) @@ -460,7 +458,7 @@ describe('transition', function () { $transitions.onEnter({ from: "A", entering: "C" }, function() { return false; }); $transitions.onError({ }, function(trans) { states.push(trans.to().name); }); - var states = []; + let states = []; Promise.resolve() .then(goFail("A", "D")) .then(() => expect(states).toEqual([ 'D' ])) @@ -471,7 +469,7 @@ describe('transition', function () { $transitions.onEnter({ from: "A", entering: "C" }, function() { throw new Error("oops!"); }); $transitions.onError({ }, function(trans) { states.push(trans.to().name); }); - var states = []; + let states = []; Promise.resolve() .then(goFail("A", "D")) .then(() => expect(states).toEqual([ 'D' ])) @@ -484,7 +482,7 @@ describe('transition', function () { $transitions.onError({ from: "A", to: "C" }, function() { hooks.push("AC"); }); $transitions.onError({ from: "A", to: "D" }, function() { hooks.push("AD"); }); - var hooks = []; + let hooks = []; Promise.resolve() .then(goFail("A", "D")) .then(() => expect(hooks).toEqual([ 'splatsplat', 'AD' ])) @@ -533,7 +531,7 @@ describe('transition', function () { })); it("return value of 'false' should reject the transition with ABORT status", ((done) => { - var states = [], rejection, transition = makeTransition("", "D"); + let states = [], rejection, transition = makeTransition("", "D"); $transitions.onEnter({ entering: "*" }, function(trans, state) { states.push(state); }); $transitions.onEnter({ from: "*", entering: "C" }, function() { return false; }); @@ -548,7 +546,7 @@ describe('transition', function () { })); it("return value of type Transition should abort the transition with SUPERSEDED status", ((done) => { - var states = [], rejection, transition = makeTransition("A", "D"); + let states = [], rejection, transition = makeTransition("A", "D"); $transitions.onEnter({ entering: "*" }, function(trans, state) { states.push(state); }); $transitions.onEnter({ from: "*", entering: "C" }, () => $state.target("B")); transition.promise.catch(function(err) { rejection = err; }); @@ -565,12 +563,12 @@ describe('transition', function () { })); it("hooks which start a new transition should cause the old transition to be rejected.", ((done) => { - var current = null; + let current = null; function currenTransition() { return current; } - var states = [], rejection, transition2, transition2success, + let states = [], rejection, transition2, transition2success, transition = current = makeTransition("A", "D", { current: currenTransition }); $transitions.onEnter({ entering: "*", to: "*" }, function(trans, state) { states.push(state); }); @@ -601,7 +599,7 @@ describe('transition', function () { })); it("hooks which return a promise should resolve the promise before continuing", (done) => { - var log = [], transition = makeTransition("A", "D"); + let log = [], transition = makeTransition("A", "D"); $transitions.onEnter({ from: "*", entering: "*" }, function(trans, state) { log.push("#"+state.name); @@ -620,9 +618,9 @@ describe('transition', function () { }); it("hooks which return a promise should resolve the promise before continuing", ((done) => { - var log = [], transition = makeTransition("A", "D"); - var $q = services.$q; - var defers = { B: $q.defer(), C: $q.defer(), D: $q.defer() }; + let log = [], transition = makeTransition("A", "D"); + let $q = services.$q; + let defers = { B: $q.defer(), C: $q.defer(), D: $q.defer() }; function resolveDeferredFor(name) { log.push("^" + name); defers[name].resolve("ok, go ahead!"); @@ -652,9 +650,9 @@ describe('transition', function () { })); it("hooks can add resolves to a $transition$ and they will be available to be injected elsewhere", ((done) => { - var log = [], transition = makeTransition("A", "D"); - var $q = services.$q; - var defer = $q.defer(); + let log = [], transition = makeTransition("A", "D"); + let $q = services.$q; + let defer = $q.defer(); $transitions.onEnter({ entering: '**'}, function logEnter(trans, state) { log.push("Entered#"+state.name); @@ -662,7 +660,7 @@ describe('transition', function () { $transitions.onEnter({ entering: "B" }, function addResolves($transition$: Transition) { log.push("adding resolve"); - var resolveFn = function () { log.push("resolving"); return defer.promise; }; + let resolveFn = function () { log.push("resolving"); return defer.promise; }; $transition$.addResolvable(new Resolvable('newResolve', resolveFn)); }); @@ -721,7 +719,7 @@ describe('transition', function () { describe('Transition() instance', function() { describe('.entering', function() { it('should return the path elements being entered', (() => { - var t = makeTransition("", "A"); + let t = makeTransition("", "A"); expect(pluck(t.entering(), 'name')).toEqual([ "A" ]); t = makeTransition("", "D"); @@ -736,7 +734,7 @@ describe('transition', function () { describe('.exiting', function() { it('should return the path elements being exited', (() => { - var t = makeTransition("D", "C"); + let t = makeTransition("D", "C"); expect(pluck(t.exiting(), 'name')).toEqual([ 'D' ]); t = makeTransition("D", "A"); @@ -746,7 +744,7 @@ describe('transition', function () { describe('.is', function() { it('should match globs', (() => { - var t = makeTransition("", "first"); + let t = makeTransition("", "first"); expect(t.is({ to: "first" })).toBe(true); expect(t.is({ from: "" })).toBe(true); @@ -765,7 +763,7 @@ describe('transition', function () { })); it('should match using functions', (() => { - var t = makeTransition("", "first"); + let t = makeTransition("", "first"); expect(t.is({ to: function(state) { return state.name === "first"; } })).toBe(true); expect(t.is({ from: function(state) { return state.name === ""; } })).toBe(true);