feat(core/linker): add SimpleChanges type to lifecycle_hooks to simplify OnChanges signature

Closes #8557
This commit is contained in:
Ward Bell
2016-05-09 15:45:04 -07:00
committed by Misko Hevery
parent 6f3a6a55a0
commit 0a872ffd38
10 changed files with 27 additions and 14 deletions

View File

@ -11,6 +11,7 @@ export {
WrappedValue,
SimpleChange,
SimpleChanges,
PipeTransform,
DefaultIterableDiffer,
IterableDiffers,

View File

@ -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.

View File

@ -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