Skip to content

Commit

Permalink
fix(lazyLoad): Allow lazyLoad stateBuilder: Get lazyLoad fn from in…
Browse files Browse the repository at this point in the history
…ternal State object, not StateDeclaration

fix(lazyLoad): Fix `State.lazyLoad` type def
  • Loading branch information
christopherthielen committed Jan 16, 2017
1 parent 7a03cac commit 9313880
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/hooks/lazyLoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {Transition} from "../transition/transition";
import {TransitionService} from "../transition/transitionService";
import {TransitionHookFn} from "../transition/interface";
import {StateDeclaration, LazyLoadResult} from "../state/interface";
import {State} from "../state/stateObject";
import {services} from "../common/coreservices";
import { StateRule } from "../url/interface";

Expand Down Expand Up @@ -57,11 +56,11 @@ const lazyLoadHook: TransitionHookFn = (transition: Transition) => {
}

// No matching state found, so let .sync() choose the best non-state match/otherwise
router.urlRouter.sync();
router.urlService.sync();
}

let promises = transition.entering()
.filter(state => !!state.lazyLoad)
.filter(state => !!state.$$state().lazyLoad)
.map(state => lazyLoadState(transition, state));

return services.$q.all(promises).then(retryTransition);
Expand All @@ -79,7 +78,7 @@ export const registerLazyLoadHook = (transitionService: TransitionService) =>
* @returns A promise for the lazy load result
*/
export function lazyLoadState(transition: Transition, state: StateDeclaration): Promise<LazyLoadResult> {
let lazyLoadFn = state.lazyLoad;
let lazyLoadFn = state.$$state().lazyLoad;

// Store/get the lazy load promise on/from the hookfn so it doesn't get re-invoked
let promise = lazyLoadFn['_promise'];
Expand Down
2 changes: 1 addition & 1 deletion src/state/stateObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class State {
public onEnter: TransitionStateHookFn;

/** Prototypally inherits from [[StateDeclaration.lazyLoad]] */
public lazyLoad: (transition: Transition) => Promise<StateDeclaration[]>;
public lazyLoad: (transition: Transition, state: StateDeclaration) => Promise<StateDeclaration[]>;

/** Prototypally inherits from [[StateDeclaration.redirectTo]] */
redirectTo: (
Expand Down

0 comments on commit 9313880

Please sign in to comment.