| 
									
										
										
										
											2016-06-23 09:47:54 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-09-27 17:12:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 09:58:52 -07:00
										 |  |  | import {ElementSchemaRegistry} from '../schema/element_schema_registry'; | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  | import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-27 17:12:25 -07:00
										 |  |  | import {CompileElement} from './compile_element'; | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  | import {CompileView} from './compile_view'; | 
					
						
							| 
									
										
										
										
											2016-10-26 16:58:35 -07:00
										 |  |  | import {bindOutputs} from './event_binder'; | 
					
						
							|  |  |  | import {bindDirectiveAfterContentLifecycleCallbacks, bindDirectiveAfterViewLifecycleCallbacks, bindDirectiveWrapperLifecycleCallbacks, bindInjectableDestroyLifecycleCallbacks, bindPipeDestroyLifecycleCallbacks} from './lifecycle_binder'; | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  | import {bindDirectiveHostProps, bindDirectiveInputs, bindRenderInputs, bindRenderText} from './property_binder'; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 09:58:52 -07:00
										 |  |  | export function bindView( | 
					
						
							|  |  |  |     view: CompileView, parsedTemplate: TemplateAst[], schemaRegistry: ElementSchemaRegistry): void { | 
					
						
							| 
									
										
										
										
											2016-11-09 16:23:41 -08:00
										 |  |  |   const visitor = new ViewBinderVisitor(view, schemaRegistry); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   templateVisitAll(visitor, parsedTemplate); | 
					
						
							| 
									
										
										
										
											2016-04-22 15:33:32 -07:00
										 |  |  |   view.pipes.forEach( | 
					
						
							|  |  |  |       (pipe) => { bindPipeDestroyLifecycleCallbacks(pipe.meta, pipe.instance, pipe.view); }); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ViewBinderVisitor implements TemplateAstVisitor { | 
					
						
							|  |  |  |   private _nodeIndex: number = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 09:58:52 -07:00
										 |  |  |   constructor(public view: CompileView, private _schemaRegistry: ElementSchemaRegistry) {} | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   visitBoundText(ast: BoundTextAst, parent: CompileElement): any { | 
					
						
							| 
									
										
										
										
											2016-11-09 16:23:41 -08:00
										 |  |  |     const node = this.view.nodes[this._nodeIndex++]; | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     bindRenderText(ast, node, this.view); | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   visitText(ast: TextAst, parent: CompileElement): any { | 
					
						
							|  |  |  |     this._nodeIndex++; | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   visitNgContent(ast: NgContentAst, parent: CompileElement): any { return null; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   visitElement(ast: ElementAst, parent: CompileElement): any { | 
					
						
							| 
									
										
										
										
											2016-11-09 16:23:41 -08:00
										 |  |  |     const compileElement = <CompileElement>this.view.nodes[this._nodeIndex++]; | 
					
						
							| 
									
										
										
										
											2016-10-26 16:58:35 -07:00
										 |  |  |     const hasEvents = bindOutputs(ast.outputs, ast.directives, compileElement, true); | 
					
						
							|  |  |  |     bindRenderInputs(ast.inputs, hasEvents, compileElement); | 
					
						
							| 
									
										
										
										
											2016-10-24 08:43:06 -07:00
										 |  |  |     ast.directives.forEach((directiveAst, dirIndex) => { | 
					
						
							| 
									
										
										
										
											2016-11-09 16:23:41 -08:00
										 |  |  |       const directiveWrapperInstance = | 
					
						
							| 
									
										
										
										
											2016-10-13 16:34:37 -07:00
										 |  |  |           compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference); | 
					
						
							| 
									
										
										
										
											2016-10-24 08:43:06 -07:00
										 |  |  |       bindDirectiveInputs(directiveAst, directiveWrapperInstance, dirIndex, compileElement); | 
					
						
							| 
									
										
										
										
											2016-10-24 09:58:52 -07:00
										 |  |  |       bindDirectiveHostProps( | 
					
						
							| 
									
										
										
										
											2016-10-26 16:58:35 -07:00
										 |  |  |           directiveAst, directiveWrapperInstance, compileElement, ast.name, this._schemaRegistry); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     templateVisitAll(this, ast.children, compileElement); | 
					
						
							|  |  |  |     // afterContent and afterView lifecycles need to be called bottom up
 | 
					
						
							|  |  |  |     // so that children are notified before parents
 | 
					
						
							| 
									
										
										
										
											2016-08-02 01:37:42 -07:00
										 |  |  |     ast.directives.forEach((directiveAst) => { | 
					
						
							| 
									
										
										
										
											2016-11-09 16:23:41 -08:00
										 |  |  |       const directiveInstance = compileElement.instances.get(directiveAst.directive.type.reference); | 
					
						
							|  |  |  |       const directiveWrapperInstance = | 
					
						
							| 
									
										
										
										
											2016-10-26 16:58:35 -07:00
										 |  |  |           compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       bindDirectiveAfterContentLifecycleCallbacks( | 
					
						
							|  |  |  |           directiveAst.directive, directiveInstance, compileElement); | 
					
						
							|  |  |  |       bindDirectiveAfterViewLifecycleCallbacks( | 
					
						
							|  |  |  |           directiveAst.directive, directiveInstance, compileElement); | 
					
						
							| 
									
										
										
										
											2016-10-26 16:58:35 -07:00
										 |  |  |       bindDirectiveWrapperLifecycleCallbacks( | 
					
						
							|  |  |  |           directiveAst, directiveWrapperInstance, compileElement); | 
					
						
							| 
									
										
										
										
											2016-08-02 01:37:42 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |     ast.providers.forEach((providerAst) => { | 
					
						
							| 
									
										
										
										
											2016-11-09 16:23:41 -08:00
										 |  |  |       const providerInstance = compileElement.instances.get(providerAst.token.reference); | 
					
						
							| 
									
										
										
										
											2016-08-02 01:37:42 -07:00
										 |  |  |       bindInjectableDestroyLifecycleCallbacks(providerAst, providerInstance, compileElement); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   visitEmbeddedTemplate(ast: EmbeddedTemplateAst, parent: CompileElement): any { | 
					
						
							| 
									
										
										
										
											2016-11-09 16:23:41 -08:00
										 |  |  |     const compileElement = <CompileElement>this.view.nodes[this._nodeIndex++]; | 
					
						
							| 
									
										
										
										
											2016-10-26 16:58:35 -07:00
										 |  |  |     bindOutputs(ast.outputs, ast.directives, compileElement, false); | 
					
						
							| 
									
										
										
										
											2016-10-24 08:43:06 -07:00
										 |  |  |     ast.directives.forEach((directiveAst, dirIndex) => { | 
					
						
							| 
									
										
										
										
											2016-11-09 16:23:41 -08:00
										 |  |  |       const directiveInstance = compileElement.instances.get(directiveAst.directive.type.reference); | 
					
						
							|  |  |  |       const directiveWrapperInstance = | 
					
						
							| 
									
										
										
										
											2016-10-13 16:34:37 -07:00
										 |  |  |           compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference); | 
					
						
							| 
									
										
										
										
											2016-10-24 08:43:06 -07:00
										 |  |  |       bindDirectiveInputs(directiveAst, directiveWrapperInstance, dirIndex, compileElement); | 
					
						
							| 
									
										
										
										
											2016-10-13 16:34:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       bindDirectiveAfterContentLifecycleCallbacks( | 
					
						
							|  |  |  |           directiveAst.directive, directiveInstance, compileElement); | 
					
						
							|  |  |  |       bindDirectiveAfterViewLifecycleCallbacks( | 
					
						
							|  |  |  |           directiveAst.directive, directiveInstance, compileElement); | 
					
						
							| 
									
										
										
										
											2016-10-26 16:58:35 -07:00
										 |  |  |       bindDirectiveWrapperLifecycleCallbacks( | 
					
						
							|  |  |  |           directiveAst, directiveWrapperInstance, compileElement); | 
					
						
							| 
									
										
										
										
											2016-08-02 01:37:42 -07:00
										 |  |  |     }); | 
					
						
							|  |  |  |     ast.providers.forEach((providerAst) => { | 
					
						
							| 
									
										
										
										
											2016-11-09 16:23:41 -08:00
										 |  |  |       const providerInstance = compileElement.instances.get(providerAst.token.reference); | 
					
						
							| 
									
										
										
										
											2016-08-02 01:37:42 -07:00
										 |  |  |       bindInjectableDestroyLifecycleCallbacks(providerAst, providerInstance, compileElement); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-10-24 09:58:52 -07:00
										 |  |  |     bindView(compileElement.embeddedView, ast.children, this._schemaRegistry); | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   visitAttr(ast: AttrAst, ctx: any): any { return null; } | 
					
						
							|  |  |  |   visitDirective(ast: DirectiveAst, ctx: any): any { return null; } | 
					
						
							|  |  |  |   visitEvent(ast: BoundEventAst, eventTargetAndNames: Map<string, BoundEventAst>): any { | 
					
						
							|  |  |  |     return null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 19:52:24 -07:00
										 |  |  |   visitReference(ast: ReferenceAst, ctx: any): any { return null; } | 
					
						
							| 
									
										
										
										
											2016-01-06 14:13:44 -08:00
										 |  |  |   visitVariable(ast: VariableAst, ctx: any): any { return null; } | 
					
						
							|  |  |  |   visitDirectiveProperty(ast: BoundDirectivePropertyAst, context: any): any { return null; } | 
					
						
							|  |  |  |   visitElementProperty(ast: BoundElementPropertyAst, context: any): any { return null; } | 
					
						
							|  |  |  | } |