feat(query): notify on changes
This commit is contained in:
@ -203,7 +203,12 @@ export class ChangeDetectorJITGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
return notifications.join("\n");
|
||||
var directiveNotifications = notifications.join("\n");
|
||||
|
||||
return `
|
||||
this.dispatcher.notifyOnAllChangesDone();
|
||||
${directiveNotifications}
|
||||
`;
|
||||
}
|
||||
|
||||
_genLocalDefinitions(): string { return this._localNames.map((n) => `var ${n};`).join("\n"); }
|
||||
|
@ -110,6 +110,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
|
||||
}
|
||||
|
||||
callOnAllChangesDone() {
|
||||
this.dispatcher.notifyOnAllChangesDone();
|
||||
var dirs = this.directiveRecords;
|
||||
for (var i = dirs.length - 1; i >= 0; --i) {
|
||||
var dir = dirs[i];
|
||||
|
@ -26,7 +26,6 @@ export class BaseQueryList<T> {
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
// TODO(rado): hook up with change detection after #995.
|
||||
fireCallbacks() {
|
||||
if (this._dirty) {
|
||||
ListWrapper.forEach(this._callbacks, (c) => c());
|
||||
|
@ -707,6 +707,15 @@ export class ElementInjector extends TreeNode<ElementInjector> {
|
||||
}
|
||||
}
|
||||
|
||||
onAllChangesDone(): void {
|
||||
if (isPresent(this._query0) && this._query0.originator === this)
|
||||
this._query0.list.fireCallbacks();
|
||||
if (isPresent(this._query1) && this._query1.originator === this)
|
||||
this._query1.list.fireCallbacks();
|
||||
if (isPresent(this._query2) && this._query2.originator === this)
|
||||
this._query2.list.fireCallbacks();
|
||||
}
|
||||
|
||||
hydrate(injector: Injector, host: ElementInjector, preBuiltObjects: PreBuiltObjects): void {
|
||||
var p = this._proto;
|
||||
|
||||
|
@ -111,6 +111,13 @@ export class AppView implements ChangeDispatcher, EventDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
notifyOnAllChangesDone(): void {
|
||||
var ei = this.elementInjectors;
|
||||
for (var i = ei.length - 1; i >= 0; i--) {
|
||||
if (isPresent(ei[i])) ei[i].onAllChangesDone();
|
||||
}
|
||||
}
|
||||
|
||||
getDirectiveFor(directive: DirectiveIndex) {
|
||||
var elementInjector = this.elementInjectors[directive.elementIndex];
|
||||
return elementInjector.getDirectiveAtIndex(directive.directiveIndex);
|
||||
|
@ -262,11 +262,15 @@ class _CodegenState {
|
||||
/// them.
|
||||
String _getCallOnAllChangesDoneBody() {
|
||||
// NOTE(kegluneq): Order is important!
|
||||
return _directiveRecords.reversed
|
||||
var directiveNotifications = _directiveRecords.reversed
|
||||
.where((rec) => rec.callOnAllChangesDone)
|
||||
.map((rec) =>
|
||||
'${_genGetDirective(rec.directiveIndex)}.onAllChangesDone();')
|
||||
.join('');
|
||||
return '''
|
||||
_dispatcher.notifyOnAllChangesDone();
|
||||
${directiveNotifications}
|
||||
''';
|
||||
}
|
||||
|
||||
String _genLocalDefinitions() =>
|
||||
|
Reference in New Issue
Block a user