Skip to content

Commit

Permalink
Fixes ui-router#788: Create OnUiParamsChanged, OnUiExit interfaces in…
Browse files Browse the repository at this point in the history
…stead of Ng2Component
  • Loading branch information
stnor committed May 28, 2020
1 parent 55de08a commit 1028768
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/directives/uiView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
} from '@uirouter/core';
import { Ng2ViewConfig } from '../statebuilders/views';
import { MergeInjector } from '../mergeInjector';
import { Ng2Component } from '../interface';

/** @hidden */
let id = 0;
Expand Down Expand Up @@ -211,7 +210,7 @@ export class UIView implements OnInit, OnDestroy {
* For each transition, checks if any param values changed and notify component
*/
private _invokeUiOnParamsChangedHook($transition$: Transition) {
const instance: Ng2Component = this._componentRef && this._componentRef.instance;
const instance = this._componentRef && this._componentRef.instance;
const uiOnParamsChanged: TransitionHookFn = instance && instance.uiOnParamsChanged;

if (isFunction(uiOnParamsChanged)) {
Expand Down
31 changes: 16 additions & 15 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/** */

import { StateDeclaration, _ViewDeclaration, Transition, HookResult } from '@uirouter/core';
import { Type, Component } from '@angular/core';
import { Type } from '@angular/core';
import { ModuleTypeCallback } from './lazyLoad/lazyLoadNgModule';

/**
Expand Down Expand Up @@ -286,18 +286,13 @@ export interface Ng2ViewDeclaration extends _ViewDeclaration {
bindings?: { [key: string]: string };
}

/**
* The shape of a controller for a view (and/or component), defining the controller callbacks.
*
* A UI-Router view has an Angular `Component` (see [[Ng2ViewDeclaration.component]]).
* The `Component` may define component-level hooks which UI-Router will call at the appropriate times.
* These callbacks are similar to Transition Hooks ([[IHookRegistry]]), but are only called if the view/component is currently active.
*
* This interface defines the UI-Router component callbacks.
*/
export interface Ng2Component extends Component {
export interface UiOnParamsChanged {
/**
* This callback is called when parameter values change
* A UI-Router view has an Angular `Component` (see [[Ng2ViewDeclaration.component]]).
* The `Component` may define component-level hooks which UI-Router will call at the appropriate times.
* These callbacks are similar to Transition Hooks ([[IHookRegistry]]), but are only called if the view/component is currently active.
*
* The uiOnParamsChanged callback is called when parameter values change.
*
* This callback is used to respond dynamic parameter values changing.
* It is called when a transition changed one or more dynamic parameter values,
Expand All @@ -323,10 +318,16 @@ export interface Ng2Component extends Component {
* }
* ```
*/
uiOnParamsChanged?(newParams: { [paramName: string]: any }, trans?: Transition): void;
uiOnParamsChanged(newParams: { [paramName: string]: any }, trans?: Transition): void;
}

export interface UiOnExit {
/**
* This callback is called when the routed component's state is about to be exited.
* A UI-Router view has an Angular `Component` (see [[Ng2ViewDeclaration.component]]).
* The `Component` may define component-level hooks which UI-Router will call at the appropriate times.
* These callbacks are similar to Transition Hooks ([[IHookRegistry]]), but are only called if the view/component is currently active.
*
* The uiCanExit callback is called when the routed component's state is about to be exited.
*
* The callback can be used to cancel or alter the new Transition that would otherwise exit the component's state.
*
Expand Down Expand Up @@ -365,5 +366,5 @@ export interface Ng2Component extends Component {
*
* @return a hook result which may cancel or alter the pending Transition (see [[HookResult]])
*/
uiCanExit?(newTransition?: Transition): HookResult;
uiCanExit(newTransition?: Transition): HookResult;
}

0 comments on commit 1028768

Please sign in to comment.