From 0a88e7b736d1254c1f87dd84c63eb94dc8bdee27 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 23 Sep 2015 11:43:31 -0700 Subject: [PATCH] feat(change detection): export SimpleChange Closes #4337 --- modules/angular2/src/core/change_detection.ts | 2 +- .../angular2/src/core/change_detection/change_detection.ts | 2 +- modules/angular2/src/core/compiler/interfaces.ts | 3 ++- .../angular2/src/core/forms/directives/ng_control_name.ts | 3 ++- .../angular2/src/core/forms/directives/ng_form_control.ts | 3 ++- modules/angular2/src/core/forms/directives/ng_model.ts | 5 ++--- modules/angular2/test/compiler/runtime_metadata_spec.ts | 5 +++-- modules/angular2/test/public_api_spec.ts | 6 ++++++ 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/modules/angular2/src/core/change_detection.ts b/modules/angular2/src/core/change_detection.ts index 3d41713cd7..7d14196b57 100644 --- a/modules/angular2/src/core/change_detection.ts +++ b/modules/angular2/src/core/change_detection.ts @@ -13,6 +13,7 @@ export { ChangeDetectorRef, WrappedValue, + SimpleChange, PipeTransform, PipeOnDestroy, IterableDiffers, @@ -21,5 +22,4 @@ export { KeyValueDiffers, KeyValueDiffer, KeyValueDifferFactory - } from './change_detection/change_detection'; diff --git a/modules/angular2/src/core/change_detection/change_detection.ts b/modules/angular2/src/core/change_detection/change_detection.ts index 27336b5c0c..594711730c 100644 --- a/modules/angular2/src/core/change_detection/change_detection.ts +++ b/modules/angular2/src/core/change_detection/change_detection.ts @@ -51,7 +51,7 @@ export {ChangeDetectorRef} from './change_detector_ref'; export {IterableDiffers, IterableDiffer, IterableDifferFactory} from './differs/iterable_differs'; export {KeyValueDiffers, KeyValueDiffer, KeyValueDifferFactory} from './differs/keyvalue_differs'; export {PipeTransform, PipeOnDestroy} from './pipe_transform'; -export {WrappedValue} from './change_detection_util'; +export {WrappedValue, SimpleChange} from './change_detection_util'; /** * Structural diffing for `Object`s and `Map`s. diff --git a/modules/angular2/src/core/compiler/interfaces.ts b/modules/angular2/src/core/compiler/interfaces.ts index 141e483c33..7c26874790 100644 --- a/modules/angular2/src/core/compiler/interfaces.ts +++ b/modules/angular2/src/core/compiler/interfaces.ts @@ -1,4 +1,5 @@ import {StringMap, MapWrapper} from 'angular2/src/core/facade/collection'; +import {SimpleChange} from 'angular2/src/core/change_detection/change_detection_util'; export enum LifecycleHooks { OnInit, @@ -60,7 +61,7 @@ export var LIFECYCLE_HOOKS_VALUES = [ * } * ``` */ -export interface OnChanges { onChanges(changes: StringMap); } +export interface OnChanges { onChanges(changes: StringMap); } /** * Notify a directive when it has been checked the first time. diff --git a/modules/angular2/src/core/forms/directives/ng_control_name.ts b/modules/angular2/src/core/forms/directives/ng_control_name.ts index ccd39258d9..fa6ed854fe 100644 --- a/modules/angular2/src/core/forms/directives/ng_control_name.ts +++ b/modules/angular2/src/core/forms/directives/ng_control_name.ts @@ -2,6 +2,7 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang'; import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async'; import {StringMap} from 'angular2/src/core/facade/collection'; import {OnChanges, OnDestroy} from 'angular2/lifecycle_hooks'; +import {SimpleChange} from 'angular2/src/core/change_detection'; import {Query, Directive} from 'angular2/src/core/metadata'; import {forwardRef, Host, SkipSelf, Binding, Inject, Optional} from 'angular2/src/core/di'; @@ -93,7 +94,7 @@ export class NgControlName extends NgControl implements OnChanges, this.validators = validators; } - onChanges(changes: StringMap) { + onChanges(changes: StringMap) { if (!this._added) { this.formDirective.addControl(this); this._added = true; diff --git a/modules/angular2/src/core/forms/directives/ng_form_control.ts b/modules/angular2/src/core/forms/directives/ng_form_control.ts index 7745998ad2..33688235fb 100644 --- a/modules/angular2/src/core/forms/directives/ng_form_control.ts +++ b/modules/angular2/src/core/forms/directives/ng_form_control.ts @@ -1,6 +1,7 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang'; import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async'; import {OnChanges} from 'angular2/lifecycle_hooks'; +import {SimpleChange} from 'angular2/src/core/change_detection'; import {Query, Directive} from 'angular2/src/core/metadata'; import {forwardRef, Binding, Inject, Optional} from 'angular2/src/core/di'; import {NgControl} from './ng_control'; @@ -80,7 +81,7 @@ export class NgFormControl extends NgControl implements OnChanges { this.validators = validators; } - onChanges(changes: StringMap): void { + onChanges(changes: StringMap): void { if (!this._added) { setUpControl(this.form, this); this.form.updateValidity(); diff --git a/modules/angular2/src/core/forms/directives/ng_model.ts b/modules/angular2/src/core/forms/directives/ng_model.ts index 9d985a4ab5..ae0cc8dc7b 100644 --- a/modules/angular2/src/core/forms/directives/ng_model.ts +++ b/modules/angular2/src/core/forms/directives/ng_model.ts @@ -1,8 +1,7 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang'; import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async'; - import {OnChanges} from 'angular2/lifecycle_hooks'; - +import {SimpleChange} from 'angular2/src/core/change_detection'; import {Query, Directive} from 'angular2/src/core/metadata'; import {forwardRef, Binding, Inject, Optional} from 'angular2/src/core/di'; import {NgControl} from './ng_control'; @@ -53,7 +52,7 @@ export class NgModel extends NgControl implements OnChanges { this.validators = validators; } - onChanges(changes: StringMap) { + onChanges(changes: StringMap) { if (!this._added) { setUpControl(this._control, this); this._control.updateValidity(); diff --git a/modules/angular2/test/compiler/runtime_metadata_spec.ts b/modules/angular2/test/compiler/runtime_metadata_spec.ts index 09c043c87c..5686202aed 100644 --- a/modules/angular2/test/compiler/runtime_metadata_spec.ts +++ b/modules/angular2/test/compiler/runtime_metadata_spec.ts @@ -29,7 +29,8 @@ import { AfterContentInit, AfterContentChecked, AfterViewInit, - AfterViewChecked + AfterViewChecked, + SimpleChange } from 'angular2/core'; import {TEST_BINDINGS} from './test_bindings'; @@ -115,7 +116,7 @@ class DirectiveWithoutModuleId { class ComponentWithEverything implements OnChanges, OnInit, DoCheck, OnDestroy, AfterContentInit, AfterContentChecked, AfterViewInit, AfterViewChecked { - onChanges(changes: StringMap): void {} + onChanges(changes: StringMap): void {} onInit(): void {} doCheck(): void {} onDestroy(): void {} diff --git a/modules/angular2/test/public_api_spec.ts b/modules/angular2/test/public_api_spec.ts index ba3c07cc6d..73e172a88b 100644 --- a/modules/angular2/test/public_api_spec.ts +++ b/modules/angular2/test/public_api_spec.ts @@ -961,6 +961,12 @@ var NG_API = [ 'SlicePipe', 'SlicePipe.supports()', 'SlicePipe.transform()', + 'SimpleChange', + 'SimpleChange.currentValue', + 'SimpleChange.currentValue=', + 'SimpleChange.previousValue', + 'SimpleChange.previousValue=', + 'SimpleChange.isFirstChange()', 'TemplateRef', 'TemplateRef.elementRef', 'TemplateRef.elementRef=',