From 1028768630c7621f5f35c5edb71ec75fc9152773 Mon Sep 17 00:00:00 2001 From: stnor Date: Thu, 28 May 2020 14:22:45 +0200 Subject: [PATCH] Fixes #788: Create OnUiParamsChanged, OnUiExit interfaces instead of Ng2Component --- src/directives/uiView.ts | 3 +-- src/interface.ts | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/directives/uiView.ts b/src/directives/uiView.ts index a9ed58018..7c8f409df 100755 --- a/src/directives/uiView.ts +++ b/src/directives/uiView.ts @@ -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; @@ -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)) { diff --git a/src/interface.ts b/src/interface.ts index 0b0291094..a09a2ec4c 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -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'; /** @@ -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, @@ -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. * @@ -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; }