| 
									
										
										
										
											2017-01-20 13:10:57 -08: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  | import {ApplicationRef} from '../application_ref'; | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  | import {ChangeDetectorRef} from '../change_detection/change_detection'; | 
					
						
							| 
									
										
										
										
											2017-02-14 21:03:18 -08:00
										 |  |  | import {Injector} from '../di'; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | import {ComponentFactory, ComponentRef} from '../linker/component_factory'; | 
					
						
							| 
									
										
										
										
											2017-03-21 08:15:10 -07:00
										 |  |  | import {ComponentFactoryBoundToModule} from '../linker/component_factory_resolver'; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | import {ElementRef} from '../linker/element_ref'; | 
					
						
							| 
									
										
										
										
											2017-03-14 16:26:17 -07:00
										 |  |  | import {NgModuleRef} from '../linker/ng_module_factory'; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | import {TemplateRef} from '../linker/template_ref'; | 
					
						
							|  |  |  | import {ViewContainerRef} from '../linker/view_container_ref'; | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:49 -08:00
										 |  |  | import {EmbeddedViewRef, InternalViewRef, ViewRef} from '../linker/view_ref'; | 
					
						
							| 
									
										
										
										
											2017-03-07 16:36:12 -08:00
										 |  |  | import {Renderer as RendererV1, Renderer2} from '../render/api'; | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  | import {Type} from '../type'; | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  | import {VERSION} from '../version'; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-21 13:36:42 -07:00
										 |  |  | import {DepFlags, ElementData, NodeDef, NodeFlags, Services, TemplateData, ViewContainerData, ViewData, ViewDefinitionFactory, ViewState, asElementData, asProviderData, asTextData} from './types'; | 
					
						
							|  |  |  | import {markParentViewsForCheck, resolveViewDefinition, rootRenderNodes, splitNamespace, tokenKey, viewParentEl} from './util'; | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  | import {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView, renderDetachView} from './view_attach'; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  | const EMPTY_CONTEXT = new Object(); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-16 17:32:14 -07:00
										 |  |  | // Attention: this function is called as top level function.
 | 
					
						
							|  |  |  | // Putting any logic in here will destroy closure tree shaking!
 | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  | export function createComponentFactory( | 
					
						
							| 
									
										
										
										
											2017-03-14 14:54:36 -07:00
										 |  |  |     selector: string, componentType: Type<any>, viewDefFactory: ViewDefinitionFactory, | 
					
						
							|  |  |  |     inputs: {[propName: string]: string}, outputs: {[propName: string]: string}, | 
					
						
							|  |  |  |     ngContentSelectors: string[]): ComponentFactory<any> { | 
					
						
							|  |  |  |   return new ComponentFactory_( | 
					
						
							| 
									
										
										
										
											2017-03-16 17:32:14 -07:00
										 |  |  |       selector, componentType, viewDefFactory, inputs, outputs, ngContentSelectors); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 23:08:19 -08:00
										 |  |  | export function getComponentViewDefinitionFactory(componentFactory: ComponentFactory<any>): | 
					
						
							|  |  |  |     ViewDefinitionFactory { | 
					
						
							|  |  |  |   return (componentFactory as ComponentFactory_).viewDefFactory; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  | class ComponentFactory_ extends ComponentFactory<any> { | 
					
						
							| 
									
										
										
										
											2017-02-27 23:08:19 -08:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * @internal | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   viewDefFactory: ViewDefinitionFactory; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   constructor( | 
					
						
							|  |  |  |       public selector: string, public componentType: Type<any>, | 
					
						
							| 
									
										
										
										
											2017-03-16 17:32:14 -07:00
										 |  |  |       viewDefFactory: ViewDefinitionFactory, private _inputs: {[propName: string]: string}, | 
					
						
							|  |  |  |       private _outputs: {[propName: string]: string}, public ngContentSelectors: string[]) { | 
					
						
							|  |  |  |     // Attention: this ctor is called as top level function.
 | 
					
						
							|  |  |  |     // Putting any logic in here will destroy closure tree shaking!
 | 
					
						
							| 
									
										
										
										
											2017-02-27 23:08:19 -08:00
										 |  |  |     super(); | 
					
						
							|  |  |  |     this.viewDefFactory = viewDefFactory; | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-16 17:32:14 -07:00
										 |  |  |   get inputs() { | 
					
						
							|  |  |  |     const inputsArr: {propName: string, templateName: string}[] = []; | 
					
						
							|  |  |  |     for (let propName in this._inputs) { | 
					
						
							|  |  |  |       const templateName = this._inputs[propName]; | 
					
						
							|  |  |  |       inputsArr.push({propName, templateName}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return inputsArr; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get outputs() { | 
					
						
							|  |  |  |     const outputsArr: {propName: string, templateName: string}[] = []; | 
					
						
							|  |  |  |     for (let propName in this._outputs) { | 
					
						
							|  |  |  |       const templateName = this._outputs[propName]; | 
					
						
							|  |  |  |       outputsArr.push({propName, templateName}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return outputsArr; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Creates a new component. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   create( | 
					
						
							| 
									
										
										
										
											2017-03-14 16:26:17 -07:00
										 |  |  |       injector: Injector, projectableNodes?: any[][], rootSelectorOrNode?: string|any, | 
					
						
							|  |  |  |       ngModule?: NgModuleRef<any>): ComponentRef<any> { | 
					
						
							|  |  |  |     if (!ngModule) { | 
					
						
							|  |  |  |       throw new Error('ngModule should be provided'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-02-27 23:08:19 -08:00
										 |  |  |     const viewDef = resolveViewDefinition(this.viewDefFactory); | 
					
						
							| 
									
										
										
										
											2017-02-21 13:56:56 -08:00
										 |  |  |     const componentNodeIndex = viewDef.nodes[0].element.componentProvider.index; | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |     const view = Services.createRootView( | 
					
						
							| 
									
										
										
										
											2017-03-14 16:26:17 -07:00
										 |  |  |         injector, projectableNodes || [], rootSelectorOrNode, viewDef, ngModule, EMPTY_CONTEXT); | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |     const component = asProviderData(view, componentNodeIndex).instance; | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |     view.renderer.setAttribute(asElementData(view, 0).renderElement, 'ng-version', VERSION.full); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |     return new ComponentRef_(view, new ViewRef_(view), component); | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  | class ComponentRef_ extends ComponentRef<any> { | 
					
						
							| 
									
										
										
										
											2017-02-15 08:36:49 -08:00
										 |  |  |   private _elDef: NodeDef; | 
					
						
							|  |  |  |   constructor(private _view: ViewData, private _viewRef: ViewRef, private _component: any) { | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |     super(); | 
					
						
							| 
									
										
										
										
											2017-02-15 08:36:49 -08:00
										 |  |  |     this._elDef = this._view.def.nodes[0]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   get location(): ElementRef { | 
					
						
							|  |  |  |     return new ElementRef(asElementData(this._view, this._elDef.index).renderElement); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   get injector(): Injector { return new Injector_(this._view, this._elDef); } | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   get instance(): any { return this._component; }; | 
					
						
							|  |  |  |   get hostView(): ViewRef { return this._viewRef; }; | 
					
						
							|  |  |  |   get changeDetectorRef(): ChangeDetectorRef { return this._viewRef; }; | 
					
						
							|  |  |  |   get componentType(): Type<any> { return <any>this._component.constructor; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   destroy(): void { this._viewRef.destroy(); } | 
					
						
							|  |  |  |   onDestroy(callback: Function): void { this._viewRef.onDestroy(callback); } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  | export function createViewContainerData( | 
					
						
							|  |  |  |     view: ViewData, elDef: NodeDef, elData: ElementData): ViewContainerData { | 
					
						
							|  |  |  |   return new ViewContainerRef_(view, elDef, elData); | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  | class ViewContainerRef_ implements ViewContainerData { | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * @internal | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   _embeddedViews: ViewData[] = []; | 
					
						
							|  |  |  |   constructor(private _view: ViewData, private _elDef: NodeDef, private _data: ElementData) {} | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   get element(): ElementRef { return new ElementRef(this._data.renderElement); } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 08:36:49 -08:00
										 |  |  |   get injector(): Injector { return new Injector_(this._view, this._elDef); } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   get parentInjector(): Injector { | 
					
						
							|  |  |  |     let view = this._view; | 
					
						
							| 
									
										
										
										
											2017-02-15 08:36:49 -08:00
										 |  |  |     let elDef = this._elDef.parent; | 
					
						
							|  |  |  |     while (!elDef && view) { | 
					
						
							|  |  |  |       elDef = viewParentEl(view); | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |       view = view.parent; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-14 16:26:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-21 08:15:10 -07:00
										 |  |  |     return view ? new Injector_(view, elDef) : new Injector_(this._view, null); | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   clear(): void { | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  |     const len = this._embeddedViews.length; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     for (let i = len - 1; i >= 0; i--) { | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |       const view = detachEmbeddedView(this._data, i); | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |       Services.destroyView(view); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |   get(index: number): ViewRef { | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  |     const view = this._embeddedViews[index]; | 
					
						
							| 
									
										
										
										
											2017-02-20 14:34:15 -08:00
										 |  |  |     if (view) { | 
					
						
							|  |  |  |       const ref = new ViewRef_(view); | 
					
						
							|  |  |  |       ref.attachToViewContainerRef(this); | 
					
						
							|  |  |  |       return ref; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return null; | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  |   get length(): number { return this._embeddedViews.length; }; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   createEmbeddedView<C>(templateRef: TemplateRef<C>, context?: C, index?: number): | 
					
						
							|  |  |  |       EmbeddedViewRef<C> { | 
					
						
							| 
									
										
										
										
											2017-02-02 15:01:35 -08:00
										 |  |  |     const viewRef = templateRef.createEmbeddedView(context || <any>{}); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     this.insert(viewRef, index); | 
					
						
							|  |  |  |     return viewRef; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createComponent<C>( | 
					
						
							|  |  |  |       componentFactory: ComponentFactory<C>, index?: number, injector?: Injector, | 
					
						
							| 
									
										
										
										
											2017-03-21 08:15:10 -07:00
										 |  |  |       projectableNodes?: any[][], ngModuleRef?: NgModuleRef<any>): ComponentRef<C> { | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |     const contextInjector = injector || this.parentInjector; | 
					
						
							| 
									
										
										
										
											2017-03-21 08:15:10 -07:00
										 |  |  |     if (!ngModuleRef && !(componentFactory instanceof ComponentFactoryBoundToModule)) { | 
					
						
							|  |  |  |       ngModuleRef = contextInjector.get(NgModuleRef); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const componentRef = | 
					
						
							|  |  |  |         componentFactory.create(contextInjector, projectableNodes, undefined, ngModuleRef); | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |     this.insert(componentRef.hostView, index); | 
					
						
							|  |  |  |     return componentRef; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   insert(viewRef: ViewRef, index?: number): ViewRef { | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |     const viewRef_ = <ViewRef_>viewRef; | 
					
						
							|  |  |  |     const viewData = viewRef_._view; | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |     attachEmbeddedView(this._view, this._data, index, viewData); | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |     viewRef_.attachToViewContainerRef(this); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |     return viewRef; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   move(viewRef: ViewRef_, currentIndex: number): ViewRef { | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  |     const previousIndex = this._embeddedViews.indexOf(viewRef._view); | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |     moveEmbeddedView(this._data, previousIndex, currentIndex); | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |     return viewRef; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   indexOf(viewRef: ViewRef): number { | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  |     return this._embeddedViews.indexOf((<ViewRef_>viewRef)._view); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   remove(index?: number): void { | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |     const viewData = detachEmbeddedView(this._data, index); | 
					
						
							| 
									
										
										
										
											2017-02-20 14:34:15 -08:00
										 |  |  |     if (viewData) { | 
					
						
							|  |  |  |       Services.destroyView(viewData); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   detach(index?: number): ViewRef { | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |     const view = detachEmbeddedView(this._data, index); | 
					
						
							|  |  |  |     return view ? new ViewRef_(view) : null; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  | export function createChangeDetectorRef(view: ViewData): ChangeDetectorRef { | 
					
						
							|  |  |  |   return new ViewRef_(view); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:49 -08:00
										 |  |  | export class ViewRef_ implements EmbeddedViewRef<any>, InternalViewRef { | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   /** @internal */ | 
					
						
							|  |  |  |   _view: ViewData; | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |   private _viewContainerRef: ViewContainerRef; | 
					
						
							|  |  |  |   private _appRef: ApplicationRef; | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |   constructor(_view: ViewData) { | 
					
						
							|  |  |  |     this._view = _view; | 
					
						
							|  |  |  |     this._viewContainerRef = null; | 
					
						
							|  |  |  |     this._appRef = null; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   get rootNodes(): any[] { return rootRenderNodes(this._view); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get context() { return this._view.context; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   get destroyed(): boolean { return (this._view.state & ViewState.Destroyed) !== 0; } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |   markForCheck(): void { markParentViewsForCheck(this._view); } | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   detach(): void { this._view.state &= ~ViewState.ChecksEnabled; } | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |   detectChanges(): void { Services.checkAndUpdateView(this._view); } | 
					
						
							|  |  |  |   checkNoChanges(): void { Services.checkNoChangesView(this._view); } | 
					
						
							| 
									
										
										
										
											2017-01-31 14:52:01 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   reattach(): void { this._view.state |= ViewState.ChecksEnabled; } | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |   onDestroy(callback: Function) { | 
					
						
							|  |  |  |     if (!this._view.disposables) { | 
					
						
							|  |  |  |       this._view.disposables = []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     this._view.disposables.push(<any>callback); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |   destroy() { | 
					
						
							|  |  |  |     if (this._appRef) { | 
					
						
							|  |  |  |       this._appRef.detachView(this); | 
					
						
							|  |  |  |     } else if (this._viewContainerRef) { | 
					
						
							|  |  |  |       this._viewContainerRef.detach(this._viewContainerRef.indexOf(this)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Services.destroyView(this._view); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |   detachFromAppRef() { | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |     this._appRef = null; | 
					
						
							| 
									
										
										
										
											2017-02-22 10:05:56 -08:00
										 |  |  |     renderDetachView(this._view); | 
					
						
							|  |  |  |     Services.dirtyParentQueries(this._view); | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   attachToAppRef(appRef: ApplicationRef) { | 
					
						
							|  |  |  |     if (this._viewContainerRef) { | 
					
						
							|  |  |  |       throw new Error('This view is already attached to a ViewContainer!'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     this._appRef = appRef; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   attachToViewContainerRef(vcRef: ViewContainerRef) { | 
					
						
							|  |  |  |     if (this._appRef) { | 
					
						
							|  |  |  |       throw new Error('This view is already attached directly to the ApplicationRef!'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     this._viewContainerRef = vcRef; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  | export function createTemplateData(view: ViewData, def: NodeDef): TemplateData { | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |   return new TemplateRef_(view, def); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  | class TemplateRef_ extends TemplateRef<any> implements TemplateData { | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * @internal | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   _projectedViews: ViewData[]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 11:33:59 -08:00
										 |  |  |   constructor(private _parentView: ViewData, private _def: NodeDef) { super(); } | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   createEmbeddedView(context: any): EmbeddedViewRef<any> { | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |     return new ViewRef_(Services.createEmbeddedView(this._parentView, this._def, context)); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   get elementRef(): ElementRef { | 
					
						
							| 
									
										
										
										
											2017-01-25 13:45:07 -08:00
										 |  |  |     return new ElementRef(asElementData(this._parentView, this._def.index).renderElement); | 
					
						
							| 
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 08:36:49 -08:00
										 |  |  | export function createInjector(view: ViewData, elDef: NodeDef): Injector { | 
					
						
							|  |  |  |   return new Injector_(view, elDef); | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  | class Injector_ implements Injector { | 
					
						
							| 
									
										
										
										
											2017-03-21 08:15:10 -07:00
										 |  |  |   constructor(private view: ViewData, private elDef: NodeDef|null) {} | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND): any { | 
					
						
							| 
									
										
										
										
											2017-03-21 08:15:10 -07:00
										 |  |  |     const allowPrivateServices = | 
					
						
							|  |  |  |         this.elDef ? (this.elDef.flags & NodeFlags.ComponentView) !== 0 : false; | 
					
						
							| 
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 |  |  |     return Services.resolveDep( | 
					
						
							| 
									
										
										
										
											2017-02-16 13:55:55 -08:00
										 |  |  |         this.view, this.elDef, allowPrivateServices, | 
					
						
							|  |  |  |         {flags: DepFlags.None, token, tokenKey: tokenKey(token)}, notFoundValue); | 
					
						
							| 
									
										
										
										
											2017-02-01 11:32:27 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function nodeValue(view: ViewData, index: number): any { | 
					
						
							|  |  |  |   const def = view.def.nodes[index]; | 
					
						
							| 
									
										
										
										
											2017-02-27 09:14:18 -08:00
										 |  |  |   if (def.flags & NodeFlags.TypeElement) { | 
					
						
							| 
									
										
										
										
											2017-03-13 10:44:12 -07:00
										 |  |  |     const elData = asElementData(view, def.index); | 
					
						
							|  |  |  |     return def.element.template ? elData.template : elData.renderElement; | 
					
						
							| 
									
										
										
										
											2017-02-27 09:14:18 -08:00
										 |  |  |   } else if (def.flags & NodeFlags.TypeText) { | 
					
						
							|  |  |  |     return asTextData(view, def.index).renderText; | 
					
						
							|  |  |  |   } else if (def.flags & (NodeFlags.CatProvider | NodeFlags.TypePipe)) { | 
					
						
							|  |  |  |     return asProviderData(view, def.index).instance; | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-27 09:14:18 -08:00
										 |  |  |   throw new Error(`Illegal state: read nodeValue for node index ${index}`); | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function createRendererV1(view: ViewData): RendererV1 { | 
					
						
							|  |  |  |   return new RendererAdapter(view.renderer); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class RendererAdapter implements RendererV1 { | 
					
						
							| 
									
										
										
										
											2017-03-07 16:36:12 -08:00
										 |  |  |   constructor(private delegate: Renderer2) {} | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |   selectRootElement(selectorOrNode: string|Element): Element { | 
					
						
							|  |  |  |     return this.delegate.selectRootElement(selectorOrNode); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createElement(parent: Element|DocumentFragment, namespaceAndName: string): Element { | 
					
						
							|  |  |  |     const [ns, name] = splitNamespace(namespaceAndName); | 
					
						
							|  |  |  |     const el = this.delegate.createElement(name, ns); | 
					
						
							|  |  |  |     if (parent) { | 
					
						
							|  |  |  |       this.delegate.appendChild(parent, el); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return el; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createViewRoot(hostElement: Element): Element|DocumentFragment { return hostElement; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createTemplateAnchor(parentElement: Element|DocumentFragment): Comment { | 
					
						
							|  |  |  |     const comment = this.delegate.createComment(''); | 
					
						
							|  |  |  |     if (parentElement) { | 
					
						
							|  |  |  |       this.delegate.appendChild(parentElement, comment); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return comment; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   createText(parentElement: Element|DocumentFragment, value: string): any { | 
					
						
							|  |  |  |     const node = this.delegate.createText(value); | 
					
						
							|  |  |  |     if (parentElement) { | 
					
						
							|  |  |  |       this.delegate.appendChild(parentElement, node); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return node; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   projectNodes(parentElement: Element|DocumentFragment, nodes: Node[]) { | 
					
						
							|  |  |  |     for (let i = 0; i < nodes.length; i++) { | 
					
						
							|  |  |  |       this.delegate.appendChild(parentElement, nodes[i]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   attachViewAfter(node: Node, viewRootNodes: Node[]) { | 
					
						
							|  |  |  |     const parentElement = this.delegate.parentNode(node); | 
					
						
							|  |  |  |     const nextSibling = this.delegate.nextSibling(node); | 
					
						
							|  |  |  |     for (let i = 0; i < viewRootNodes.length; i++) { | 
					
						
							|  |  |  |       this.delegate.insertBefore(parentElement, viewRootNodes[i], nextSibling); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   detachView(viewRootNodes: (Element|Text|Comment)[]) { | 
					
						
							|  |  |  |     for (let i = 0; i < viewRootNodes.length; i++) { | 
					
						
							|  |  |  |       const node = viewRootNodes[i]; | 
					
						
							|  |  |  |       const parentElement = this.delegate.parentNode(node); | 
					
						
							|  |  |  |       this.delegate.removeChild(parentElement, node); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   destroyView(hostElement: Element|DocumentFragment, viewAllNodes: Node[]) { | 
					
						
							|  |  |  |     for (let i = 0; i < viewAllNodes.length; i++) { | 
					
						
							|  |  |  |       this.delegate.destroyNode(viewAllNodes[i]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   listen(renderElement: any, name: string, callback: Function): Function { | 
					
						
							|  |  |  |     return this.delegate.listen(renderElement, name, <any>callback); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   listenGlobal(target: string, name: string, callback: Function): Function { | 
					
						
							|  |  |  |     return this.delegate.listen(target, name, <any>callback); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setElementProperty( | 
					
						
							|  |  |  |       renderElement: Element|DocumentFragment, propertyName: string, propertyValue: any): void { | 
					
						
							|  |  |  |     this.delegate.setProperty(renderElement, propertyName, propertyValue); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setElementAttribute(renderElement: Element, namespaceAndName: string, attributeValue: string): | 
					
						
							|  |  |  |       void { | 
					
						
							|  |  |  |     const [ns, name] = splitNamespace(namespaceAndName); | 
					
						
							|  |  |  |     if (attributeValue != null) { | 
					
						
							|  |  |  |       this.delegate.setAttribute(renderElement, name, attributeValue, ns); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       this.delegate.removeAttribute(renderElement, name, ns); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setBindingDebugInfo(renderElement: Element, propertyName: string, propertyValue: string): void {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setElementClass(renderElement: Element, className: string, isAdd: boolean): void { | 
					
						
							|  |  |  |     if (isAdd) { | 
					
						
							|  |  |  |       this.delegate.addClass(renderElement, className); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       this.delegate.removeClass(renderElement, className); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setElementStyle(renderElement: HTMLElement, styleName: string, styleValue: string): void { | 
					
						
							|  |  |  |     if (styleValue != null) { | 
					
						
							| 
									
										
										
										
											2017-03-13 09:45:04 -07:00
										 |  |  |       this.delegate.setStyle(renderElement, styleName, styleValue); | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2017-03-13 09:45:04 -07:00
										 |  |  |       this.delegate.removeStyle(renderElement, styleName); | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   invokeElementMethod(renderElement: Element, methodName: string, args: any[]): void { | 
					
						
							|  |  |  |     (renderElement as any)[methodName].apply(renderElement, args); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setText(renderNode: Text, text: string): void { this.delegate.setValue(renderNode, text); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 23:08:19 -08:00
										 |  |  |   animate(): any { throw new Error('Renderer.animate is no longer supported!'); } | 
					
						
							| 
									
										
										
										
											2017-02-17 08:56:36 -08:00
										 |  |  | } |