From d48fae356666bd3c410fcffd962d61388b6f3a69 Mon Sep 17 00:00:00 2001 From: yjbanov Date: Fri, 22 May 2015 13:14:59 -0700 Subject: [PATCH] fix(core): resurrect OnChange interface --- modules/angular2/core.ts | 3 +- .../angular2/src/core/compiler/interfaces.ts | 7 ++++ .../core/compiler/integration_dart_spec.dart | 35 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 modules/angular2/src/core/compiler/interfaces.ts diff --git a/modules/angular2/core.ts b/modules/angular2/core.ts index 72059d0fc0..2de58ce01d 100644 --- a/modules/angular2/core.ts +++ b/modules/angular2/core.ts @@ -9,9 +9,10 @@ export * from './src/core/annotations/view'; export * from './src/core/application'; export * from './src/core/application_tokens'; export * from './src/core/annotations/di'; -export * from './src/core/compiler/query_list'; export * from './src/core/compiler/compiler'; +export * from './src/core/compiler/interfaces'; +export * from './src/core/compiler/query_list'; // TODO(tbosch): remove this once render migration is complete export * from './src/render/dom/compiler/template_loader'; diff --git a/modules/angular2/src/core/compiler/interfaces.ts b/modules/angular2/src/core/compiler/interfaces.ts new file mode 100644 index 0000000000..5a327f513f --- /dev/null +++ b/modules/angular2/src/core/compiler/interfaces.ts @@ -0,0 +1,7 @@ +import {StringMap} from 'angular2/src/facade/collection'; + +/** + * Defines lifecycle method [onChange] called after all of component's bound + * properties are updated. + */ +export interface OnChange { onChange(changes: StringMap): void; } diff --git a/modules/angular2/test/core/compiler/integration_dart_spec.dart b/modules/angular2/test/core/compiler/integration_dart_spec.dart index acf6e908f7..1322f98448 100644 --- a/modules/angular2/test/core/compiler/integration_dart_spec.dart +++ b/modules/angular2/test/core/compiler/integration_dart_spec.dart @@ -104,6 +104,24 @@ main() { }); })); }); + + describe('OnChange', () { + it('should be notified of changes', + inject([TestBed, AsyncTestCompleter], (tb, async) { + tb.overrideView(Dummy, new View( + template: '''''', + directives: [OnChangeComponent] + )); + + tb.createView(Dummy).then((view) { + view.detectChanges(); + var cmp = view.rawView.elementInjectors[0].get(OnChangeComponent); + expect(cmp.prop).toEqual('hello'); + expect(cmp.changes.containsKey('prop')).toEqual(true); + async.done(); + }); + })); + }); } @Component(selector: 'dummy') @@ -168,3 +186,20 @@ class PropertyAccess { class NoPropertyAccess { final model = new PropModel(); } + +@Component( + selector: 'on-change', + // TODO: needed because of https://github.com/angular/angular/issues/2120 + lifecycle: const [onChange], + properties: const { 'prop': 'prop' } +) +@View(template: '') +class OnChangeComponent implements OnChange { + Map changes; + String prop; + + @override + void onChange(Map changes) { + this.changes = changes; + } +}