fix(core): resurrect OnChange interface
This commit is contained in:
parent
3525c9c074
commit
d48fae3566
@ -9,9 +9,10 @@ export * from './src/core/annotations/view';
|
|||||||
export * from './src/core/application';
|
export * from './src/core/application';
|
||||||
export * from './src/core/application_tokens';
|
export * from './src/core/application_tokens';
|
||||||
export * from './src/core/annotations/di';
|
export * from './src/core/annotations/di';
|
||||||
export * from './src/core/compiler/query_list';
|
|
||||||
|
|
||||||
export * from './src/core/compiler/compiler';
|
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
|
// TODO(tbosch): remove this once render migration is complete
|
||||||
export * from './src/render/dom/compiler/template_loader';
|
export * from './src/render/dom/compiler/template_loader';
|
||||||
|
7
modules/angular2/src/core/compiler/interfaces.ts
Normal file
7
modules/angular2/src/core/compiler/interfaces.ts
Normal file
@ -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<string, any>): void; }
|
@ -104,6 +104,24 @@ main() {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('OnChange', () {
|
||||||
|
it('should be notified of changes',
|
||||||
|
inject([TestBed, AsyncTestCompleter], (tb, async) {
|
||||||
|
tb.overrideView(Dummy, new View(
|
||||||
|
template: '''<on-change [prop]="'hello'"></on-change>''',
|
||||||
|
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')
|
@Component(selector: 'dummy')
|
||||||
@ -168,3 +186,20 @@ class PropertyAccess {
|
|||||||
class NoPropertyAccess {
|
class NoPropertyAccess {
|
||||||
final model = new PropModel();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user