@@ -64,6 +64,7 @@ import {
6464 * }
6565 * }
6666 *
67+ * ChangeDetector0.prototype.notifyOnAllChangesDone = function() {}
6768 *
6869 * ChangeDetector0.prototype.hydrate = function(context, locals) {
6970 * this.context = context;
@@ -96,31 +97,35 @@ var UTIL = "ChangeDetectionUtil";
9697var DISPATCHER_ACCESSOR = "this.dispatcher" ;
9798var PIPE_REGISTRY_ACCESSOR = "this.pipeRegistry" ;
9899var PROTOS_ACCESSOR = "this.protos" ;
100+ var MEMENTOS_ACCESSOR = "this.directiveMementos" ;
99101var CONTEXT_ACCESSOR = "this.context" ;
100102var CHANGE_LOCAL = "change" ;
101103var CHANGES_LOCAL = "changes" ;
102104var LOCALS_ACCESSOR = "this.locals" ;
103105var TEMP_LOCAL = "temp" ;
104106
105- function typeTemplate ( type :string , cons :string , detectChanges :string , setContext :string ) :string {
107+ function typeTemplate ( type :string , cons :string , detectChanges :string ,
108+ notifyOnAllChangesDone :string , setContext :string ) :string {
106109 return `
107110${ cons }
108111${ detectChanges }
112+ ${ notifyOnAllChangesDone }
109113${ setContext } ;
110114
111115return function(dispatcher, pipeRegistry) {
112- return new ${ type } (dispatcher, pipeRegistry, protos);
116+ return new ${ type } (dispatcher, pipeRegistry, protos, directiveMementos );
113117}
114118` ;
115119}
116120
117121function constructorTemplate ( type :string , fieldsDefinitions :string ) :string {
118122 return `
119- var ${ type } = function ${ type } (dispatcher, pipeRegistry, protos) {
123+ var ${ type } = function ${ type } (dispatcher, pipeRegistry, protos, directiveMementos ) {
120124${ ABSTRACT_CHANGE_DETECTOR } .call(this);
121125${ DISPATCHER_ACCESSOR } = dispatcher;
122126${ PIPE_REGISTRY_ACCESSOR } = pipeRegistry;
123127${ PROTOS_ACCESSOR } = protos;
128+ ${ MEMENTOS_ACCESSOR } = directiveMementos;
124129${ fieldsDefinitions }
125130}
126131
@@ -157,6 +162,18 @@ ${type}.prototype.detectChangesInRecords = function(throwOnChange) {
157162` ;
158163}
159164
165+ function notifyOnAllChangesDoneTemplate ( type :string , body :string ) :string {
166+ return `
167+ ${ type } .prototype.notifyOnAllChangesDone = function() {
168+ ${ body }
169+ }
170+ ` ;
171+ }
172+
173+ function onAllChangesDoneTemplate ( index :number ) :string {
174+ return `${ DISPATCHER_ACCESSOR } .onAllChangesDone(${ MEMENTOS_ACCESSOR } [${ index } ]);` ;
175+ }
176+
160177
161178function bodyTemplate ( localDefinitions :string , changeDefinitions :string , records :string ) :string {
162179 return `
@@ -247,14 +264,16 @@ function addSimpleChangeRecordTemplate(protoIndex:number, oldValue:string, newVa
247264export class ChangeDetectorJITGenerator {
248265 typeName :string ;
249266 records :List < ProtoRecord > ;
267+ directiveMementos :List ;
250268 localNames :List < String > ;
251269 changeNames :List < String > ;
252270 fieldNames :List < String > ;
253271 pipeNames :List < String > ;
254272
255- constructor ( typeName :string , records :List < ProtoRecord > ) {
273+ constructor ( typeName :string , records :List < ProtoRecord > , directiveMementos : List ) {
256274 this . typeName = typeName ;
257275 this . records = records ;
276+ this . directiveMementos = directiveMementos ;
258277
259278 this . localNames = this . getLocalNames ( records ) ;
260279 this . changeNames = this . getChangeNames ( this . localNames ) ;
@@ -284,8 +303,10 @@ export class ChangeDetectorJITGenerator {
284303 }
285304
286305 generate ( ) :Function {
287- var text = typeTemplate ( this . typeName , this . genConstructor ( ) , this . genDetectChanges ( ) , this . genHydrate ( ) ) ;
288- return new Function ( 'AbstractChangeDetector' , 'ChangeDetectionUtil' , 'protos' , text ) ( AbstractChangeDetector , ChangeDetectionUtil , this . records ) ;
306+ var text = typeTemplate ( this . typeName , this . genConstructor ( ) , this . genDetectChanges ( ) ,
307+ this . genNotifyOnAllChangesDone ( ) , this . genHydrate ( ) ) ;
308+ return new Function ( 'AbstractChangeDetector' , 'ChangeDetectionUtil' , 'protos' , 'directiveMementos' , text )
309+ ( AbstractChangeDetector , ChangeDetectionUtil , this . records , this . directiveMementos ) ;
289310 }
290311
291312 genConstructor ( ) :string {
@@ -319,6 +340,20 @@ export class ChangeDetectorJITGenerator {
319340 return detectChangesTemplate ( this . typeName , body ) ;
320341 }
321342
343+ genNotifyOnAllChangesDone ( ) :string {
344+ var notifications = [ ] ;
345+ var mementos = this . directiveMementos ;
346+
347+ for ( var i = mementos . length - 1 ; i >= 0 ; -- i ) {
348+ var memento = mementos [ i ] ;
349+ if ( memento . notifyOnAllChangesDone ) {
350+ notifications . push ( onAllChangesDoneTemplate ( i ) ) ;
351+ }
352+ }
353+
354+ return notifyOnAllChangesDoneTemplate ( this . typeName , notifications . join ( ";\n" ) ) ;
355+ }
356+
322357 genBody ( ) :string {
323358 var rec = this . records . map ( ( r ) => this . genRecord ( r ) ) . join ( "\n" ) ;
324359 return bodyTemplate ( this . genLocalDefinitions ( ) , this . genChangeDefinitions ( ) , rec ) ;
0 commit comments