import {isPresent} from 'angular2/src/facade/lang'; import {Promise} from 'angular2/src/facade/async'; import {List, Map} from 'angular2/src/facade/collection'; import {ASTWithSource} from 'angular2/change_detection'; /** * General notes: * * The methods for creating / destroying views in this API are used in the AppViewHydrator * and RenderViewHydrator as well. * * We are already parsing expressions on the render side: * - this makes the ElementBinders more compact * (e.g. no need to distinguish interpolations from regular expressions from literals) * - allows to retrieve which properties should be accessed from the event * by looking at the expression * - we need the parse at least for the `template` attribute to match * directives in it * - render compiler is not on the critical path as * its output will be stored in precompiled templates. */ export class EventBinding { fullName: string; // name/target:name, e.g "click", "window:resize" source: ASTWithSource; constructor(fullName :string, source: ASTWithSource) { this.fullName = fullName; this.source = source; } } export class ElementBinder { index:number; parentIndex:number; distanceToParent:number; directives:List; nestedProtoView:ProtoViewDto; propertyBindings: Map; variableBindings: Map; // Note: this contains a preprocessed AST // that replaced the values that should be extracted from the element // with a local name eventBindings: List; textBindings: List; readAttributes: Map; constructor({ index, parentIndex, distanceToParent, directives, nestedProtoView, propertyBindings, variableBindings, eventBindings, textBindings, readAttributes }) { this.index = index; this.parentIndex = parentIndex; this.distanceToParent = distanceToParent; this.directives = directives; this.nestedProtoView = nestedProtoView; this.propertyBindings = propertyBindings; this.variableBindings = variableBindings; this.eventBindings = eventBindings; this.textBindings = textBindings; this.readAttributes = readAttributes; } } export class DirectiveBinder { // Index into the array of directives in the View instance directiveIndex:any; propertyBindings: Map; // Note: this contains a preprocessed AST // that replaced the values that should be extracted from the element // with a local name eventBindings: List; hostPropertyBindings: Map; constructor({ directiveIndex, propertyBindings, eventBindings, hostPropertyBindings }) { this.directiveIndex = directiveIndex; this.propertyBindings = propertyBindings; this.eventBindings = eventBindings; this.hostPropertyBindings = hostPropertyBindings; } } export class ProtoViewDto { // A view that contains the host element with bound // component directive. // Contains a view of type #COMPONENT_VIEW_TYPE. static get HOST_VIEW_TYPE() { return 0; } // The view of the component // Can contain 0 to n views of type #EMBEDDED_VIEW_TYPE static get COMPONENT_VIEW_TYPE() { return 1; } // A view that is embedded into another View via a