import {isPresent, isBlank, RegExpWrapper} from 'angular2/src/core/facade/lang'; import {Promise} from 'angular2/src/core/facade/async'; import {Map, MapWrapper, StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection'; import { ASTWithSource, ChangeDetectionStrategy } from 'angular2/src/core/change_detection/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 { constructor(public fullName: string, public source: ASTWithSource) {} } export enum PropertyBindingType { PROPERTY, ATTRIBUTE, CLASS, STYLE } export class ElementPropertyBinding { constructor(public type: PropertyBindingType, public astWithSource: ASTWithSource, public property: string, public unit: string = null) {} } export class RenderElementBinder { index: number; parentIndex: number; distanceToParent: number; directives: DirectiveBinder[]; nestedProtoView: ProtoViewDto; propertyBindings: ElementPropertyBinding[]; variableBindings: Map; // Note: this contains a preprocessed AST // that replaced the values that should be extracted from the element // with a local name eventBindings: EventBinding[]; readAttributes: Map; constructor({index, parentIndex, distanceToParent, directives, nestedProtoView, propertyBindings, variableBindings, eventBindings, readAttributes}: { index?: number, parentIndex?: number, distanceToParent?: number, directives?: DirectiveBinder[], nestedProtoView?: ProtoViewDto, propertyBindings?: ElementPropertyBinding[], variableBindings?: Map, eventBindings?: EventBinding[], readAttributes?: Map } = {}) { 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.readAttributes = readAttributes; } } export class DirectiveBinder { // Index into the array of directives in the View instance directiveIndex: number; propertyBindings: Map; // Note: this contains a preprocessed AST // that replaced the values that should be extracted from the element // with a local name eventBindings: EventBinding[]; hostPropertyBindings: ElementPropertyBinding[]; constructor({directiveIndex, propertyBindings, eventBindings, hostPropertyBindings}: { directiveIndex?: number, propertyBindings?: Map, eventBindings?: EventBinding[], hostPropertyBindings?: ElementPropertyBinding[] }) { this.directiveIndex = directiveIndex; this.propertyBindings = propertyBindings; this.eventBindings = eventBindings; this.hostPropertyBindings = hostPropertyBindings; } } export enum ViewType { // A view that contains the host element with bound component directive. // Contains a COMPONENT view HOST, // The view of the component // Can contain 0 to n EMBEDDED views COMPONENT, // A view that is embedded into another View via a