Skip to content

Commit d48fae3

Browse files
committed
fix(core): resurrect OnChange interface
1 parent 3525c9c commit d48fae3

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

modules/angular2/core.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export * from './src/core/annotations/view';
99
export * from './src/core/application';
1010
export * from './src/core/application_tokens';
1111
export * from './src/core/annotations/di';
12-
export * from './src/core/compiler/query_list';
1312

1413
export * from './src/core/compiler/compiler';
14+
export * from './src/core/compiler/interfaces';
15+
export * from './src/core/compiler/query_list';
1516

1617
// TODO(tbosch): remove this once render migration is complete
1718
export * from './src/render/dom/compiler/template_loader';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {StringMap} from 'angular2/src/facade/collection';
2+
3+
/**
4+
* Defines lifecycle method [onChange] called after all of component's bound
5+
* properties are updated.
6+
*/
7+
export interface OnChange { onChange(changes: StringMap<string, any>): void; }

modules/angular2/test/core/compiler/integration_dart_spec.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ main() {
104104
});
105105
}));
106106
});
107+
108+
describe('OnChange', () {
109+
it('should be notified of changes',
110+
inject([TestBed, AsyncTestCompleter], (tb, async) {
111+
tb.overrideView(Dummy, new View(
112+
template: '''<on-change [prop]="'hello'"></on-change>''',
113+
directives: [OnChangeComponent]
114+
));
115+
116+
tb.createView(Dummy).then((view) {
117+
view.detectChanges();
118+
var cmp = view.rawView.elementInjectors[0].get(OnChangeComponent);
119+
expect(cmp.prop).toEqual('hello');
120+
expect(cmp.changes.containsKey('prop')).toEqual(true);
121+
async.done();
122+
});
123+
}));
124+
});
107125
}
108126

109127
@Component(selector: 'dummy')
@@ -168,3 +186,20 @@ class PropertyAccess {
168186
class NoPropertyAccess {
169187
final model = new PropModel();
170188
}
189+
190+
@Component(
191+
selector: 'on-change',
192+
// TODO: needed because of https://github.com/angular/angular/issues/2120
193+
lifecycle: const [onChange],
194+
properties: const { 'prop': 'prop' }
195+
)
196+
@View(template: '')
197+
class OnChangeComponent implements OnChange {
198+
Map changes;
199+
String prop;
200+
201+
@override
202+
void onChange(Map changes) {
203+
this.changes = changes;
204+
}
205+
}

0 commit comments

Comments
 (0)