feat(core/linker): add SimpleChanges type to lifecycle_hooks to simplify OnChanges signature
Closes #8557
This commit is contained in:
parent
6f3a6a55a0
commit
0a872ffd38
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
OnChanges,
|
||||
OnDestroy,
|
||||
SimpleChange,
|
||||
SimpleChanges,
|
||||
Directive,
|
||||
forwardRef,
|
||||
Host,
|
||||
|
@ -114,7 +114,7 @@ export class NgControlName extends NgControl implements OnChanges,
|
|||
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
||||
}
|
||||
|
||||
ngOnChanges(changes: {[key: string]: SimpleChange}) {
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (!this._added) {
|
||||
this.formDirective.addControl(this);
|
||||
this._added = true;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
OnChanges,
|
||||
SimpleChange,
|
||||
SimpleChanges,
|
||||
Directive,
|
||||
forwardRef,
|
||||
Inject,
|
||||
|
@ -100,7 +100,7 @@ export class NgFormControl extends NgControl implements OnChanges {
|
|||
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
||||
}
|
||||
|
||||
ngOnChanges(changes: {[key: string]: SimpleChange}): void {
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (this._isControlChanged(changes)) {
|
||||
setUpControl(this.form, this);
|
||||
this.form.updateValueAndValidity({emitEvent: false});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {
|
||||
SimpleChange,
|
||||
SimpleChanges,
|
||||
OnChanges,
|
||||
Directive,
|
||||
forwardRef,
|
||||
|
@ -116,7 +116,7 @@ export class NgFormModel extends ControlContainer implements Form,
|
|||
super();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: {[key: string]: SimpleChange}): void {
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
this._checkFormPresent();
|
||||
if (StringMapWrapper.contains(changes, "form")) {
|
||||
var sync = composeValidators(this._validators);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
OnChanges,
|
||||
SimpleChange,
|
||||
SimpleChanges,
|
||||
Directive,
|
||||
forwardRef,
|
||||
Inject,
|
||||
|
@ -72,7 +72,7 @@ export class NgModel extends NgControl implements OnChanges {
|
|||
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
||||
}
|
||||
|
||||
ngOnChanges(changes: {[key: string]: SimpleChange}) {
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (!this._added) {
|
||||
setUpControl(this._control, this);
|
||||
this._control.updateValueAndValidity({emitEvent: false});
|
||||
|
|
|
@ -28,7 +28,7 @@ import {
|
|||
AfterContentChecked,
|
||||
AfterViewInit,
|
||||
AfterViewChecked,
|
||||
SimpleChange,
|
||||
SimpleChanges,
|
||||
provide
|
||||
} from '@angular/core';
|
||||
|
||||
|
@ -141,7 +141,7 @@ class ComponentWithoutModuleId {
|
|||
class ComponentWithEverything implements OnChanges,
|
||||
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterContentChecked, AfterViewInit,
|
||||
AfterViewChecked {
|
||||
ngOnChanges(changes: {[key: string]: SimpleChange}): void {}
|
||||
ngOnChanges(changes: SimpleChanges): void {}
|
||||
ngOnInit(): void {}
|
||||
ngDoCheck(): void {}
|
||||
ngOnDestroy(): void {}
|
||||
|
|
|
@ -11,6 +11,7 @@ export {
|
|||
|
||||
WrappedValue,
|
||||
SimpleChange,
|
||||
SimpleChanges,
|
||||
PipeTransform,
|
||||
DefaultIterableDiffer,
|
||||
IterableDiffers,
|
||||
|
|
|
@ -41,6 +41,7 @@ export {
|
|||
looseIdentical,
|
||||
uninitialized
|
||||
} from './change_detection_util';
|
||||
export {SimpleChanges} from '../metadata/lifecycle_hooks';
|
||||
|
||||
/**
|
||||
* Structural diffing for `Object`s and `Map`s.
|
||||
|
|
|
@ -11,6 +11,15 @@ export enum LifecycleHooks {
|
|||
AfterViewChecked
|
||||
}
|
||||
|
||||
/**
|
||||
* A `changes` object whose keys are property names and
|
||||
* values are instances of {@link SimpleChange}. See {@link OnChanges}
|
||||
*/
|
||||
export interface SimpleChanges {[propName: string]: SimpleChange};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export var LIFECYCLE_HOOKS_VALUES = [
|
||||
LifecycleHooks.OnInit,
|
||||
LifecycleHooks.OnDestroy,
|
||||
|
@ -53,7 +62,7 @@ export var LIFECYCLE_HOOKS_VALUES = [
|
|||
* class MyComponent implements OnChanges {
|
||||
* @Input() myProp: any;
|
||||
*
|
||||
* ngOnChanges(changes: {[propName: string]: SimpleChange}) {
|
||||
* ngOnChanges(changes: SimpleChanges) {
|
||||
* console.log('ngOnChanges - myProp = ' + changes['myProp'].currentValue);
|
||||
* }
|
||||
* }
|
||||
|
@ -72,7 +81,7 @@ export var LIFECYCLE_HOOKS_VALUES = [
|
|||
* bootstrap(App).catch(err => console.error(err));
|
||||
* ```
|
||||
*/
|
||||
export abstract class OnChanges { abstract ngOnChanges(changes: {[key: string]: SimpleChange}); }
|
||||
export abstract class OnChanges { abstract ngOnChanges(changes: SimpleChanges); }
|
||||
|
||||
/**
|
||||
* Implement this interface to execute custom initialization logic after your directive's
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
ComponentFactory,
|
||||
ComponentRef,
|
||||
SimpleChange,
|
||||
SimpleChanges,
|
||||
ReflectiveInjector
|
||||
} from '@angular/core';
|
||||
import {NG1_SCOPE} from './constants';
|
||||
|
@ -19,7 +20,7 @@ const INITIAL_VALUE = {
|
|||
export class DowngradeNg2ComponentAdapter {
|
||||
component: any = null;
|
||||
inputChangeCount: number = 0;
|
||||
inputChanges: {[key: string]: SimpleChange} = null;
|
||||
inputChanges: SimpleChanges = null;
|
||||
componentRef: ComponentRef<any> = null;
|
||||
changeDetector: ChangeDetectorRef = null;
|
||||
componentScope: angular.IScope;
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
OnInit,
|
||||
OnChanges,
|
||||
SimpleChange,
|
||||
SimpleChanges,
|
||||
Type
|
||||
} from '@angular/core';
|
||||
import {
|
||||
|
@ -248,7 +249,7 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
|||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: {[name: string]: SimpleChange}) {
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
for (var name in changes) {
|
||||
if ((<Object>changes).hasOwnProperty(name)) {
|
||||
var change: SimpleChange = changes[name];
|
||||
|
|
Loading…
Reference in New Issue