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AC;AAChD,OAAG,SAAS,EAAI,SAAO,CAAC;EAC1B;AAAA,AACF;AAxLA,KAAK,eAAe,AAAC,sDACb,EAAC,GAAE,CAAG,UAAS,AAAD,CAAG;AAAC,YAmLS,oBAAmB,IApLtD,MAAK,KAAgB,UAC4B;EAAC,CAAC,CAAC,CAAC;AAwLrD","file":"angular2/src/core/compiler/proto_view_factory.es6","sourcesContent":["import {Injectable} from 'angular2/di';\nimport {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';\nimport {isPresent, isBlank} from 'angular2/src/facade/lang';\nimport {reflector} from 'angular2/src/reflection/reflection';\n\nimport {ChangeDetection} from 'angular2/change_detection';\nimport {Component, Viewport, DynamicComponent} from '../annotations/annotations';\n\nimport * as renderApi from 'angular2/src/render/api';\nimport {AppProtoView} from './view';\nimport {ProtoElementInjector, DirectiveBinding} from './element_injector';\n\n@Injectable()\nexport class ProtoViewFactory {\n _changeDetection:ChangeDetection;\n\n constructor(changeDetection:ChangeDetection) {\n this._changeDetection = changeDetection;\n }\n\n createProtoView(componentBinding:DirectiveBinding, renderProtoView: renderApi.ProtoViewDto, directives:List<DirectiveBinding>):AppProtoView {\n var protoChangeDetector;\n if (isBlank(componentBinding)) {\n protoChangeDetector = this._changeDetection.createProtoChangeDetector('root', null);\n } else {\n var componentAnnotation:Component = componentBinding.annotation;\n protoChangeDetector = this._changeDetection.createProtoChangeDetector(\n 'dummy', componentAnnotation.changeDetection\n );\n }\n var protoView = new AppProtoView(renderProtoView.render, protoChangeDetector);\n\n for (var i=0; i<renderProtoView.elementBinders.length; i++) {\n var renderElementBinder = renderProtoView.elementBinders[i];\n var sortedDirectives = new SortedDirectives(renderElementBinder.directives, directives);\n var parentPeiWithDistance = this._findParentProtoElementInjectorWithDistance(\n i, protoView.elementBinders, renderProtoView.elementBinders\n );\n var protoElementInjector = this._createProtoElementInjector(\n i, parentPeiWithDistance,\n sortedDirectives, renderElementBinder\n );\n this._createElementBinder(\n protoView, renderElementBinder, protoElementInjector, sortedDirectives\n );\n this._createDirectiveBinders(protoView, sortedDirectives);\n }\n MapWrapper.forEach(renderProtoView.variableBindings, (mappedName, varName) => {\n protoView.bindVariable(varName, mappedName);\n });\n return protoView;\n }\n\n _findParentProtoElementInjectorWithDistance(binderIndex, elementBinders, renderElementBinders) {\n var distance = 0;\n do {\n var renderElementBinder = renderElementBinders[binderIndex];\n binderIndex = renderElementBinder.parentIndex;\n if (binderIndex !== -1) {\n distance += renderElementBinder.distanceToParent;\n var elementBinder = elementBinders[binderIndex];\n if (isPresent(elementBinder.protoElementInjector)) {\n return new ParentProtoElementInjectorWithDistance(elementBinder.protoElementInjector, distance);\n }\n }\n } while (binderIndex !== -1);\n return new ParentProtoElementInjectorWithDistance(null, -1);\n }\n\n _createProtoElementInjector(binderIndex, parentPeiWithDistance, sortedDirectives, renderElementBinder) {\n var protoElementInjector = null;\n // Create a protoElementInjector for any element that either has bindings *or* has one\n // or more var- defined. Elements with a var- defined need a their own element injector\n // so that, when hydrating, $implicit can be set to the element.\n var hasVariables = MapWrapper.size(renderElementBinder.variableBindings) > 0;\n if (sortedDirectives.directives.length > 0 || hasVariables) {\n protoElementInjector = new ProtoElementInjector(\n parentPeiWithDistance.protoElementInjector, binderIndex,\n sortedDirectives.directives,\n isPresent(sortedDirectives.componentDirective), parentPeiWithDistance.distance\n );\n protoElementInjector.attributes = renderElementBinder.readAttributes;\n // Viewport directives are treated differently than other element with var- definitions.\n if (hasVariables && !isPresent(sortedDirectives.viewportDirective)) {\n protoElementInjector.exportComponent = isPresent(sortedDirectives.componentDirective);\n protoElementInjector.exportElement = isBlank(sortedDirectives.componentDirective);\n\n // experiment\n var exportImplicitName = MapWrapper.get(renderElementBinder.variableBindings, '\\$implicit');\n if (isPresent(exportImplicitName)) {\n protoElementInjector.exportImplicitName = exportImplicitName;\n }\n }\n }\n return protoElementInjector;\n }\n\n _createElementBinder(protoView, renderElementBinder, protoElementInjector, sortedDirectives) {\n var parent = null;\n if (renderElementBinder.parentIndex !== -1) {\n parent = protoView.elementBinders[renderElementBinder.parentIndex];\n }\n var elBinder = protoView.bindElement(\n parent,\n renderElementBinder.distanceToParent,\n protoElementInjector,\n sortedDirectives.componentDirective,\n sortedDirectives.viewportDirective\n );\n // text nodes\n for (var i=0; i<renderElementBinder.textBindings.length; i++) {\n protoView.bindTextNode(renderElementBinder.textBindings[i]);\n }\n // element properties\n MapWrapper.forEach(renderElementBinder.propertyBindings, (astWithSource, propertyName) => {\n protoView.bindElementProperty(astWithSource, propertyName);\n });\n // events\n protoView.bindEvent(renderElementBinder.eventBindings, -1);\n // variables\n // The view's locals needs to have a full set of variable names at construction time\n // in order to prevent new variables from being set later in the lifecycle. Since we don't want\n // to actually create variable bindings for the $implicit bindings, add to the\n // protoLocals manually.\n MapWrapper.forEach(renderElementBinder.variableBindings, (mappedName, varName) => {\n MapWrapper.set(protoView.protoLocals, mappedName, null);\n });\n return elBinder;\n }\n\n _createDirectiveBinders(protoView, sortedDirectives) {\n for (var i=0; i<sortedDirectives.renderDirectives.length; i++) {\n var renderDirectiveMetadata = sortedDirectives.renderDirectives[i];\n // directive properties\n MapWrapper.forEach(renderDirectiveMetadata.propertyBindings, (astWithSource, propertyName) => {\n // TODO: these setters should eventually be created by change detection, to make\n // it monomorphic!\n var setter = reflector.setter(propertyName);\n protoView.bindDirectiveProperty(i, astWithSource, propertyName, setter);\n });\n // directive events\n protoView.bindEvent(renderDirectiveMetadata.eventBindings, i);\n }\n }\n\n}\n\nclass SortedDirectives {\n componentDirective: DirectiveBinding;\n viewportDirective: DirectiveBinding;\n renderDirectives: List<renderApi.DirectiveMetadata>;\n directives: List<DirectiveBinding>;\n\n constructor(renderDirectives, allDirectives) {\n this.renderDirectives = [];\n this.directives = [];\n this.viewportDirective = null;\n this.componentDirective = null;\n ListWrapper.forEach(renderDirectives, (renderDirectiveMetadata) => {\n var directiveBinding = allDirectives[renderDirectiveMetadata.directiveIndex];\n if ((directiveBinding.annotation instanceof Component) || (directiveBinding.annotation instanceof DynamicComponent)) {\n // component directives need to be the first binding in ElementInjectors!\n this.componentDirective = directiveBinding;\n ListWrapper.insert(this.renderDirectives, 0, renderDirectiveMetadata);\n ListWrapper.insert(this.directives, 0, directiveBinding);\n } else {\n if (directiveBinding.annotation instanceof Viewport) {\n this.viewportDirective = directiveBinding;\n }\n ListWrapper.push(this.renderDirectives, renderDirectiveMetadata);\n ListWrapper.push(this.directives, directiveBinding);\n }\n });\n\n }\n}\n\nclass ParentProtoElementInjectorWithDistance {\n protoElementInjector:ProtoElementInjector;\n distance:number;\n constructor(protoElementInjector:ProtoElementInjector, distance:number) {\n this.protoElementInjector = protoElementInjector;\n this.distance = distance;\n }\n}\n"]}