style(render): idiomatic TS

This commit is contained in:
Victor Berchet
2015-06-12 23:11:11 +02:00
parent cebf69933c
commit d64cc8d87d
28 changed files with 108 additions and 311 deletions

View File

@ -20,13 +20,7 @@ import {ASTWithSource} from 'angular2/change_detection';
* its output will be stored in precompiled templates. * its output will be stored in precompiled templates.
*/ */
export class EventBinding { export class EventBinding {
fullName: string; // name/target:name, e.g "click", "window:resize" constructor(public fullName: string, public source: ASTWithSource) {}
source: ASTWithSource;
constructor(fullName: string, source: ASTWithSource) {
this.fullName = fullName;
this.source = source;
}
} }
export class ElementBinder { export class ElementBinder {

View File

@ -8,20 +8,13 @@ import {CompileStep} from './compile_step';
* Right now it only allows to add a parent element. * Right now it only allows to add a parent element.
*/ */
export class CompileControl { export class CompileControl {
_steps: List<CompileStep>; _currentStepIndex: number = 0;
_currentStepIndex: number; _parent: CompileElement = null;
_parent: CompileElement; _results = null;
_results; _additionalChildren = null;
_additionalChildren;
_ignoreCurrentElement: boolean; _ignoreCurrentElement: boolean;
constructor(steps) { constructor(public _steps: List<CompileStep>) {}
this._steps = steps;
this._currentStepIndex = 0;
this._parent = null;
this._results = null;
this._additionalChildren = null;
}
// only public so that it can be used by compile_pipeline // only public so that it can be used by compile_pipeline
internalProcess(results, startStepIndex, parent: CompileElement, current: CompileElement) { internalProcess(results, startStepIndex, parent: CompileElement, current: CompileElement) {

View File

@ -10,30 +10,19 @@ import {ProtoViewBuilder, ElementBinderBuilder} from '../view/proto_view_builder
* by the CompileSteps starting out with the pure HTMLElement. * by the CompileSteps starting out with the pure HTMLElement.
*/ */
export class CompileElement { export class CompileElement {
element; _attrs: Map<string, string> = null;
_attrs: Map<string, string>; _classList: List<string> = null;
_classList: List<string>; isViewRoot: boolean = false;
isViewRoot: boolean; // inherited down to children if they don't have an own protoView
inheritedProtoView: ProtoViewBuilder; inheritedProtoView: ProtoViewBuilder = null;
distanceToInheritedBinder: number; distanceToInheritedBinder: number = 0;
inheritedElementBinder: ElementBinderBuilder; // inherited down to children if they don't have an own elementBinder
compileChildren: boolean; inheritedElementBinder: ElementBinderBuilder = null;
compileChildren: boolean = true;
elementDescription: string; // e.g. '<div [class]="foo">' : used to provide context in case of elementDescription: string; // e.g. '<div [class]="foo">' : used to provide context in case of
// error // error
constructor(element, compilationUnit = '') { constructor(public element, compilationUnit: string = '') {
this.element = element;
this._attrs = null;
this._classList = null;
this.isViewRoot = false;
// inherited down to children if they don't have
// an own protoView
this.inheritedProtoView = null;
// inherited down to children if they don't have
// an own elementBinder
this.inheritedElementBinder = null;
this.distanceToInheritedBinder = 0;
this.compileChildren = true;
// description is calculated here as compilation steps may change the element // description is calculated here as compilation steps may change the element
var tplDesc = assertionsEnabled() ? getElementDescription(element) : null; var tplDesc = assertionsEnabled() ? getElementDescription(element) : null;
if (compilationUnit !== '') { if (compilationUnit !== '') {

View File

@ -18,14 +18,7 @@ export class CompileStepFactory {
} }
export class DefaultStepFactory extends CompileStepFactory { export class DefaultStepFactory extends CompileStepFactory {
_parser: Parser; constructor(public _parser: Parser, public _shadowDomStrategy: ShadowDomStrategy) { super(); }
_shadowDomStrategy: ShadowDomStrategy;
constructor(parser: Parser, shadowDomStrategy) {
super();
this._parser = parser;
this._shadowDomStrategy = shadowDomStrategy;
}
createSteps(template: ViewDefinition, subTaskPromises: List<Promise<any>>) { createSteps(template: ViewDefinition, subTaskPromises: List<Promise<any>>) {
return [ return [

View File

@ -25,15 +25,10 @@ import {PropertySetterFactory} from '../view/property_setter_factory';
* the CompilePipeline and the CompileSteps. * the CompilePipeline and the CompileSteps.
*/ */
export class DomCompiler extends RenderCompiler { export class DomCompiler extends RenderCompiler {
_templateLoader: TemplateLoader; _propertySetterFactory: PropertySetterFactory = new PropertySetterFactory();
_stepFactory: CompileStepFactory;
_propertySetterFactory: PropertySetterFactory;
constructor(stepFactory: CompileStepFactory, templateLoader: TemplateLoader) { constructor(public _stepFactory: CompileStepFactory, public _templateLoader: TemplateLoader) {
super(); super();
this._templateLoader = templateLoader;
this._stepFactory = stepFactory;
this._propertySetterFactory = new PropertySetterFactory();
} }
compile(template: ViewDefinition): Promise<ProtoViewDto> { compile(template: ViewDefinition): Promise<ProtoViewDto> {

View File

@ -18,25 +18,18 @@ import {CompileControl} from './compile_control';
import {DirectiveMetadata} from '../../api'; import {DirectiveMetadata} from '../../api';
import {dashCaseToCamelCase, camelCaseToDashCase, EVENT_TARGET_SEPARATOR} from '../util'; import {dashCaseToCamelCase, camelCaseToDashCase, EVENT_TARGET_SEPARATOR} from '../util';
import { import {DirectiveBuilder} from '../view/proto_view_builder';
DirectiveBuilder
} from '../view/proto_view_builder'
/** /**
* Parses the directives on a single element. Assumes ViewSplitter has already created * Parses the directives on a single element. Assumes ViewSplitter has already created
* <template> elements for template directives. * <template> elements for template directives.
*/ */
export class DirectiveParser implements CompileStep { export class DirectiveParser implements CompileStep {
_selectorMatcher: SelectorMatcher; _selectorMatcher: SelectorMatcher = new SelectorMatcher();
_directives: List<DirectiveMetadata>;
_parser: Parser;
constructor(parser: Parser, directives: List<DirectiveMetadata>) { constructor(public _parser: Parser, public _directives: List<DirectiveMetadata>) {
this._parser = parser; for (var i = 0; i < _directives.length; i++) {
this._selectorMatcher = new SelectorMatcher(); var directive = _directives[i];
this._directives = directives;
for (var i = 0; i < directives.length; i++) {
var directive = directives[i];
var selector = CssSelector.parse(directive.selector); var selector = CssSelector.parse(directive.selector);
this._ensureComponentOnlyHasElementSelector(selector, directive); this._ensureComponentOnlyHasElementSelector(selector, directive);
this._selectorMatcher.addSelectables(selector, i); this._selectorMatcher.addSelectables(selector, i);

View File

@ -23,9 +23,7 @@ var BIND_NAME_REGEXP = RegExpWrapper.create(
* Parses the property bindings on a single element. * Parses the property bindings on a single element.
*/ */
export class PropertyBindingParser implements CompileStep { export class PropertyBindingParser implements CompileStep {
_parser: Parser; constructor(public _parser: Parser) {}
constructor(parser: Parser) { this._parser = parser; }
process(parent: CompileElement, current: CompileElement, control: CompileControl) { process(parent: CompileElement, current: CompileElement, control: CompileControl) {
var attrs = current.attrs(); var attrs = current.attrs();

View File

@ -26,10 +26,11 @@ var _SELECTOR_REGEXP = RegExpWrapper.create(
* of selecting subsets out of them. * of selecting subsets out of them.
*/ */
export class CssSelector { export class CssSelector {
element: string; element: string = null;
classNames: List<string>; classNames: List<string> = [];
attrs: List<string>; attrs: List<string> = [];
notSelectors: List<CssSelector>; notSelectors: List<CssSelector> = [];
static parse(selector: string): List<CssSelector> { static parse(selector: string): List<CssSelector> {
var results = ListWrapper.create(); var results = ListWrapper.create();
var _addResult = (res, cssSel) => { var _addResult = (res, cssSel) => {
@ -78,13 +79,6 @@ export class CssSelector {
return results; return results;
} }
constructor() {
this.element = null;
this.classNames = ListWrapper.create();
this.attrs = ListWrapper.create();
this.notSelectors = ListWrapper.create();
}
isElementSelector(): boolean { isElementSelector(): boolean {
return isPresent(this.element) && ListWrapper.isEmpty(this.classNames) && return isPresent(this.element) && ListWrapper.isEmpty(this.classNames) &&
ListWrapper.isEmpty(this.attrs) && this.notSelectors.length === 0; ListWrapper.isEmpty(this.attrs) && this.notSelectors.length === 0;
@ -147,26 +141,13 @@ export class SelectorMatcher {
return notMatcher; return notMatcher;
} }
private _elementMap: Map<string, List<string>>; private _elementMap: Map<string, List<string>> = MapWrapper.create();
private _elementPartialMap: Map<string, SelectorMatcher>; private _elementPartialMap: Map<string, SelectorMatcher> = MapWrapper.create();
private _classMap: Map<string, List<string>>; private _classMap: Map<string, List<string>> = MapWrapper.create();
private _classPartialMap: Map<string, SelectorMatcher>; private _classPartialMap: Map<string, SelectorMatcher> = MapWrapper.create();
private _attrValueMap: Map<string, Map<string, List<string>>>; private _attrValueMap: Map<string, Map<string, List<string>>> = MapWrapper.create();
private _attrValuePartialMap: Map<string, Map<string, SelectorMatcher>>; private _attrValuePartialMap: Map<string, Map<string, SelectorMatcher>> = MapWrapper.create();
private _listContexts: List<SelectorListContext>; private _listContexts: List<SelectorListContext> = [];
constructor() {
this._elementMap = MapWrapper.create();
this._elementPartialMap = MapWrapper.create();
this._classMap = MapWrapper.create();
this._classPartialMap = MapWrapper.create();
this._attrValueMap = MapWrapper.create();
this._attrValuePartialMap = MapWrapper.create();
this._listContexts = ListWrapper.create();
}
addSelectables(cssSelectors: List<CssSelector>, callbackCtxt?: any) { addSelectables(cssSelectors: List<CssSelector>, callbackCtxt?: any) {
var listContext = null; var listContext = null;
@ -192,7 +173,6 @@ export class SelectorMatcher {
var attrs = cssSelector.attrs; var attrs = cssSelector.attrs;
var selectable = new SelectorContext(cssSelector, callbackCtxt, listContext); var selectable = new SelectorContext(cssSelector, callbackCtxt, listContext);
if (isPresent(element)) { if (isPresent(element)) {
var isTerminal = attrs.length === 0 && classNames.length === 0; var isTerminal = attrs.length === 0 && classNames.length === 0;
if (isTerminal) { if (isTerminal) {
@ -353,27 +333,18 @@ export class SelectorMatcher {
class SelectorListContext { class SelectorListContext {
selectors: List<CssSelector>; alreadyMatched: boolean = false;
alreadyMatched: boolean;
constructor(selectors: List<CssSelector>) { constructor(public selectors: List<CssSelector>) {}
this.selectors = selectors;
this.alreadyMatched = false;
}
} }
// Store context to pass back selector and context when a selector is matched // Store context to pass back selector and context when a selector is matched
class SelectorContext { class SelectorContext {
selector: CssSelector;
notSelectors: List<CssSelector>; notSelectors: List<CssSelector>;
cbContext; // callback context
listContext: SelectorListContext;
constructor(selector: CssSelector, cbContext: any, listContext: SelectorListContext) { constructor(public selector: CssSelector, public cbContext: any,
this.selector = selector; public listContext: SelectorListContext) {
this.notSelectors = selector.notSelectors; this.notSelectors = selector.notSelectors;
this.cbContext = cbContext;
this.listContext = listContext;
} }
finalize(cssSelector: CssSelector, callback /*: (CssSelector, any) => void*/) { finalize(cssSelector: CssSelector, callback /*: (CssSelector, any) => void*/) {

View File

@ -15,13 +15,9 @@ import {UrlResolver} from 'angular2/src/services/url_resolver';
*/ */
@Injectable() @Injectable()
export class TemplateLoader { export class TemplateLoader {
_xhr: XHR; _htmlCache: StringMap<string, /*element*/ any> = StringMapWrapper.create();
_htmlCache: StringMap<string, /*element*/ any>;
constructor(xhr: XHR, urlResolver: UrlResolver) { constructor(public _xhr: XHR, urlResolver: UrlResolver) {}
this._xhr = xhr;
this._htmlCache = StringMapWrapper.create();
}
load(template: ViewDefinition): Promise</*element*/ any> { load(template: ViewDefinition): Promise</*element*/ any> {
if (isPresent(template.template)) { if (isPresent(template.template)) {

View File

@ -11,9 +11,7 @@ import {CompileControl} from './compile_control';
* Parses interpolations in direct text child nodes of the current element. * Parses interpolations in direct text child nodes of the current element.
*/ */
export class TextInterpolationParser implements CompileStep { export class TextInterpolationParser implements CompileStep {
_parser: Parser; constructor(public _parser: Parser) {}
constructor(parser: Parser) { this._parser = parser; }
process(parent: CompileElement, current: CompileElement, control: CompileControl) { process(parent: CompileElement, current: CompileElement, control: CompileControl) {
if (!current.compileChildren) { if (!current.compileChildren) {

View File

@ -26,9 +26,7 @@ import {dashCaseToCamelCase} from '../util';
* which should not descend into the nested view. * which should not descend into the nested view.
*/ */
export class ViewSplitter implements CompileStep { export class ViewSplitter implements CompileStep {
_parser: Parser; constructor(public _parser: Parser) {}
constructor(parser: Parser) { this._parser = parser; }
process(parent: CompileElement, current: CompileElement, control: CompileControl) { process(parent: CompileElement, current: CompileElement, control: CompileControl) {
var attrs = current.attrs(); var attrs = current.attrs();

View File

@ -26,15 +26,11 @@ export const DOCUMENT_TOKEN = CONST_EXPR(new OpaqueToken('DocumentToken'));
@Injectable() @Injectable()
export class DomRenderer extends Renderer { export class DomRenderer extends Renderer {
_eventManager: EventManager;
_shadowDomStrategy: ShadowDomStrategy;
_document; _document;
constructor(eventManager: EventManager, shadowDomStrategy: ShadowDomStrategy, constructor(public _eventManager: EventManager, public _shadowDomStrategy: ShadowDomStrategy,
@Inject(DOCUMENT_TOKEN) document) { @Inject(DOCUMENT_TOKEN) document) {
super(); super();
this._eventManager = eventManager;
this._shadowDomStrategy = shadowDomStrategy;
this._document = document; this._document = document;
} }

View File

@ -6,14 +6,9 @@ import {NgZone} from 'angular2/src/core/zone/ng_zone';
var BUBBLE_SYMBOL = '^'; var BUBBLE_SYMBOL = '^';
export class EventManager { export class EventManager {
_plugins: List<EventManagerPlugin>; constructor(public _plugins: List<EventManagerPlugin>, public _zone: NgZone) {
_zone: NgZone; for (var i = 0; i < _plugins.length; i++) {
_plugins[i].manager = this;
constructor(plugins: List<EventManagerPlugin>, zone: NgZone) {
this._zone = zone;
this._plugins = plugins;
for (var i = 0; i < plugins.length; i++) {
plugins[i].manager = this;
} }
} }

View File

@ -14,7 +14,7 @@ class ContentStrategy {
* and thus does not affect redistribution. * and thus does not affect redistribution.
*/ */
class RenderedContent extends ContentStrategy { class RenderedContent extends ContentStrategy {
beginScript; beginScript: any;
endScript; endScript;
constructor(contentEl) { constructor(contentEl) {
@ -47,12 +47,9 @@ class RenderedContent extends ContentStrategy {
* and thus does not get rendered but only affect the distribution of its parent component. * and thus does not get rendered but only affect the distribution of its parent component.
*/ */
class IntermediateContent extends ContentStrategy { class IntermediateContent extends ContentStrategy {
destinationLightDom: ldModule.LightDom; constructor(public destinationLightDom: ldModule.LightDom) {
constructor(destinationLightDom: ldModule.LightDom) {
super(); super();
this.nodes = []; this.nodes = [];
this.destinationLightDom = destinationLightDom;
} }
insert(nodes: List</*node*/ any>) { insert(nodes: List</*node*/ any>) {
@ -63,15 +60,9 @@ class IntermediateContent extends ContentStrategy {
export class Content { export class Content {
select: string; private _strategy: ContentStrategy = null;
private _strategy: ContentStrategy;
contentStartElement;
constructor(contentStartEl, selector: string) { constructor(public contentStartElement, public select: string) {}
this.select = selector;
this.contentStartElement = contentStartEl;
this._strategy = null;
}
init(destinationLightDom: ldModule.LightDom) { init(destinationLightDom: ldModule.LightDom) {
this._strategy = isPresent(destinationLightDom) ? new IntermediateContent(destinationLightDom) : this._strategy = isPresent(destinationLightDom) ? new IntermediateContent(destinationLightDom) :

View File

@ -27,11 +27,8 @@ import {
* - see `ShadowCss` for more information and limitations. * - see `ShadowCss` for more information and limitations.
*/ */
export class EmulatedScopedShadowDomStrategy extends EmulatedUnscopedShadowDomStrategy { export class EmulatedScopedShadowDomStrategy extends EmulatedUnscopedShadowDomStrategy {
styleInliner: StyleInliner; constructor(public styleInliner: StyleInliner, styleUrlResolver: StyleUrlResolver, styleHost) {
constructor(styleInliner: StyleInliner, styleUrlResolver: StyleUrlResolver, styleHost) {
super(styleUrlResolver, styleHost); super(styleUrlResolver, styleHost);
this.styleInliner = styleInliner;
} }
processStyleElement(hostComponentId: string, templateUrl: string, styleEl): Promise<any> { processStyleElement(hostComponentId: string, templateUrl: string, styleEl): Promise<any> {

View File

@ -19,14 +19,7 @@ import {insertSharedStyleText} from './util';
* - you can **not** use shadow DOM specific selectors in the styles * - you can **not** use shadow DOM specific selectors in the styles
*/ */
export class EmulatedUnscopedShadowDomStrategy extends ShadowDomStrategy { export class EmulatedUnscopedShadowDomStrategy extends ShadowDomStrategy {
styleUrlResolver: StyleUrlResolver; constructor(public styleUrlResolver: StyleUrlResolver, public styleHost) { super(); }
styleHost;
constructor(styleUrlResolver: StyleUrlResolver, styleHost) {
super();
this.styleUrlResolver = styleUrlResolver;
this.styleHost = styleHost;
}
hasNativeContentElement(): boolean { return false; } hasNativeContentElement(): boolean { return false; }

View File

@ -18,17 +18,14 @@ export class LightDom {
// The light DOM of the element is enclosed inside the lightDomView // The light DOM of the element is enclosed inside the lightDomView
lightDomView: viewModule.DomView; lightDomView: viewModule.DomView;
// The shadow DOM // The shadow DOM
shadowDomView: viewModule.DomView; shadowDomView: viewModule.DomView = null;
// The nodes of the light DOM // The nodes of the light DOM
nodes: List</*node*/ any>; nodes: List</*node*/ any>;
private _roots: List<_Root>; private _roots: List<_Root> = null;
constructor(lightDomView: viewModule.DomView, element) { constructor(lightDomView: viewModule.DomView, element) {
this.lightDomView = lightDomView; this.lightDomView = lightDomView;
this.nodes = DOM.childNodesAsList(element); this.nodes = DOM.childNodesAsList(element);
this._roots = null;
this.shadowDomView = null;
} }
attachShadowDomView(shadowDomView: viewModule.DomView) { this.shadowDomView = shadowDomView; } attachShadowDomView(shadowDomView: viewModule.DomView) { this.shadowDomView = shadowDomView; }

View File

@ -14,12 +14,7 @@ import {ShadowDomStrategy} from './shadow_dom_strategy';
*/ */
@Injectable() @Injectable()
export class NativeShadowDomStrategy extends ShadowDomStrategy { export class NativeShadowDomStrategy extends ShadowDomStrategy {
styleUrlResolver: StyleUrlResolver; constructor(public styleUrlResolver: StyleUrlResolver) { super(); }
constructor(styleUrlResolver: StyleUrlResolver) {
super();
this.styleUrlResolver = styleUrlResolver;
}
prepareShadowRoot(el) { return DOM.createShadowRoot(el); } prepareShadowRoot(el) { return DOM.createShadowRoot(el); }

View File

@ -137,9 +137,9 @@ import {
*/ */
export class ShadowCss { export class ShadowCss {
strictStyling: boolean; strictStyling: boolean = true;
constructor() { this.strictStyling = true; } constructor() {}
/* /*
* Shim a style element with the given selector. Returns cssText that can * Shim a style element with the given selector. Returns cssText that can

View File

@ -11,16 +11,8 @@ import {ViewDefinition} from '../../api';
import {ShadowDomStrategy} from './shadow_dom_strategy'; import {ShadowDomStrategy} from './shadow_dom_strategy';
export class ShadowDomCompileStep implements CompileStep { export class ShadowDomCompileStep implements CompileStep {
_shadowDomStrategy: ShadowDomStrategy; constructor(public _shadowDomStrategy: ShadowDomStrategy, public _template: ViewDefinition,
_template: ViewDefinition; public _subTaskPromises: List<Promise<any>>) {}
_subTaskPromises: List<Promise<any>>;
constructor(shadowDomStrategy: ShadowDomStrategy, template: ViewDefinition,
subTaskPromises: List<Promise<any>>) {
this._shadowDomStrategy = shadowDomStrategy;
this._template = template;
this._subTaskPromises = subTaskPromises;
}
process(parent: CompileElement, current: CompileElement, control: CompileControl) { process(parent: CompileElement, current: CompileElement, control: CompileControl) {
var tagName = DOM.tagName(current.element).toUpperCase(); var tagName = DOM.tagName(current.element).toUpperCase();

View File

@ -25,15 +25,8 @@ import {
*/ */
@Injectable() @Injectable()
export class StyleInliner { export class StyleInliner {
_xhr: XHR; constructor(public _xhr: XHR, public _styleUrlResolver: StyleUrlResolver,
_urlResolver: UrlResolver; public _urlResolver: UrlResolver) {}
_styleUrlResolver: StyleUrlResolver;
constructor(xhr: XHR, styleUrlResolver: StyleUrlResolver, urlResolver: UrlResolver) {
this._xhr = xhr;
this._urlResolver = urlResolver;
this._styleUrlResolver = styleUrlResolver;
}
/** /**
* Inline the @imports rules in the given CSS text. * Inline the @imports rules in the given CSS text.

View File

@ -10,9 +10,7 @@ import {UrlResolver} from 'angular2/src/services/url_resolver';
*/ */
@Injectable() @Injectable()
export class StyleUrlResolver { export class StyleUrlResolver {
_resolver: UrlResolver; constructor(public _resolver: UrlResolver) {}
constructor(resolver: UrlResolver) { this._resolver = resolver; }
resolveUrls(cssText: string, baseUrl: string) { resolveUrls(cssText: string, baseUrl: string) {
cssText = this._replaceUrls(cssText, _cssUrlRe, baseUrl); cssText = this._replaceUrls(cssText, _cssUrlRe, baseUrl);

View File

@ -49,25 +49,9 @@ export class ElementBinder {
} }
export class Event { export class Event {
name: string; constructor(public name: string, public target: string, public fullName: string) {}
target: string;
fullName: string;
constructor(name: string, target: string, fullName: string) {
this.name = name;
this.target = target;
this.fullName = fullName;
}
} }
export class HostAction { export class HostAction {
actionName: string; constructor(public actionName: string, public actionExpression: string, public expression: AST) {}
actionExpression: string;
expression: AST;
constructor(actionName: string, actionExpression: string, expression: AST) {
this.actionName = actionName;
this.actionExpression = actionExpression;
this.expression = expression;
}
} }

View File

@ -22,13 +22,11 @@ export class PropertySetterFactory {
private _lazyPropertySettersCache: StringMap<string, Function> = StringMapWrapper.create(); private _lazyPropertySettersCache: StringMap<string, Function> = StringMapWrapper.create();
private _eagerPropertySettersCache: StringMap<string, Function> = StringMapWrapper.create(); private _eagerPropertySettersCache: StringMap<string, Function> = StringMapWrapper.create();
private _innerHTMLSetterCache: Function; private _innerHTMLSetterCache: Function = (el, value) => DOM.setInnerHTML(el, value);
private _attributeSettersCache: StringMap<string, Function> = StringMapWrapper.create(); private _attributeSettersCache: StringMap<string, Function> = StringMapWrapper.create();
private _classSettersCache: StringMap<string, Function> = StringMapWrapper.create(); private _classSettersCache: StringMap<string, Function> = StringMapWrapper.create();
private _styleSettersCache: StringMap<string, Function> = StringMapWrapper.create(); private _styleSettersCache: StringMap<string, Function> = StringMapWrapper.create();
constructor() { this._innerHTMLSetterCache = (el, value) => DOM.setInnerHTML(el, value); }
createSetter(protoElement: /*element*/ any, isNgComponent: boolean, property: string): Function { createSetter(protoElement: /*element*/ any, isNgComponent: boolean, property: string): Function {
var setterFn, styleParts, styleSuffix; var setterFn, styleParts, styleSuffix;
if (StringWrapper.startsWith(property, ATTRIBUTE_PREFIX)) { if (StringWrapper.startsWith(property, ATTRIBUTE_PREFIX)) {

View File

@ -13,11 +13,7 @@ export function resolveInternalDomProtoView(protoViewRef: RenderProtoViewRef) {
} }
export class DomProtoViewRef extends RenderProtoViewRef { export class DomProtoViewRef extends RenderProtoViewRef {
_protoView: DomProtoView; constructor(public _protoView: DomProtoView) { super(); }
constructor(protoView: DomProtoView) {
super();
this._protoView = protoView;
}
} }
export class DomProtoView { export class DomProtoView {

View File

@ -146,39 +146,21 @@ export class ProtoViewBuilder {
} }
export class ElementBinderBuilder { export class ElementBinderBuilder {
element; parent: ElementBinderBuilder = null;
index: number; distanceToParent: number = 0;
parent: ElementBinderBuilder; directives: List<DirectiveBuilder> = [];
distanceToParent: number; nestedProtoView: ProtoViewBuilder = null;
directives: List<DirectiveBuilder>; propertyBindings: Map<string, ASTWithSource> = MapWrapper.create();
nestedProtoView: ProtoViewBuilder; variableBindings: Map<string, string> = MapWrapper.create();
propertyBindings: Map<string, ASTWithSource>; eventBindings: List<api.EventBinding> = [];
variableBindings: Map<string, string>; eventBuilder: EventBuilder = new EventBuilder();
eventBindings: List<api.EventBinding>; textBindingIndices: List<number> = [];
eventBuilder: EventBuilder; textBindings: List<ASTWithSource> = [];
textBindingIndices: List<number>; contentTagSelector: string = null;
textBindings: List<ASTWithSource>; readAttributes: Map<string, string> = MapWrapper.create();
contentTagSelector: string; componentId: string = null;
readAttributes: Map<string, string>;
componentId: string;
constructor(index, element, description) { constructor(public index: number, public element, description: string) {}
this.element = element;
this.index = index;
this.parent = null;
this.distanceToParent = 0;
this.directives = [];
this.nestedProtoView = null;
this.propertyBindings = MapWrapper.create();
this.variableBindings = MapWrapper.create();
this.eventBindings = ListWrapper.create();
this.eventBuilder = new EventBuilder();
this.textBindings = [];
this.textBindingIndices = [];
this.contentTagSelector = null;
this.componentId = null;
this.readAttributes = MapWrapper.create();
}
setParent(parent: ElementBinderBuilder, distanceToParent): ElementBinderBuilder { setParent(parent: ElementBinderBuilder, distanceToParent): ElementBinderBuilder {
this.parent = parent; this.parent = parent;
@ -243,21 +225,13 @@ export class ElementBinderBuilder {
} }
export class DirectiveBuilder { export class DirectiveBuilder {
directiveIndex: number; propertyBindings: Map<string, ASTWithSource> = MapWrapper.create();
propertyBindings: Map<string, ASTWithSource>; hostPropertyBindings: Map<string, ASTWithSource> = MapWrapper.create();
hostPropertyBindings: Map<string, ASTWithSource>; hostActions: List<HostAction> = [];
hostActions: List<HostAction>; eventBindings: List<api.EventBinding> = [];
eventBindings: List<api.EventBinding>; eventBuilder: EventBuilder = new EventBuilder();
eventBuilder: EventBuilder;
constructor(directiveIndex) { constructor(public directiveIndex: number) {}
this.directiveIndex = directiveIndex;
this.propertyBindings = MapWrapper.create();
this.hostPropertyBindings = MapWrapper.create();
this.hostActions = ListWrapper.create();
this.eventBindings = ListWrapper.create();
this.eventBuilder = new EventBuilder();
}
bindProperty(name, expression) { MapWrapper.set(this.propertyBindings, name, expression); } bindProperty(name, expression) { MapWrapper.set(this.propertyBindings, name, expression); }
@ -275,18 +249,12 @@ export class DirectiveBuilder {
} }
export class EventBuilder extends AstTransformer { export class EventBuilder extends AstTransformer {
locals: List<AST>; locals: List<AST> = [];
localEvents: List<Event>; localEvents: List<Event> = [];
globalEvents: List<Event>; globalEvents: List<Event> = [];
_implicitReceiver: AST; _implicitReceiver: AST = new ImplicitReceiver();
constructor() { constructor() { super(); }
super();
this.locals = [];
this.localEvents = [];
this.globalEvents = [];
this._implicitReceiver = new ImplicitReceiver();
}
add(name: string, source: ASTWithSource, target: string): api.EventBinding { add(name: string, source: ASTWithSource, target: string): api.EventBinding {
// TODO(tbosch): reenable this when we are parsing element properties // TODO(tbosch): reenable this when we are parsing element properties

View File

@ -14,11 +14,7 @@ export function resolveInternalDomView(viewRef: RenderViewRef) {
} }
export class DomViewRef extends RenderViewRef { export class DomViewRef extends RenderViewRef {
_view: DomView; constructor(public _view: DomView) { super(); }
constructor(view: DomView) {
super();
this._view = view;
}
} }
@ -28,20 +24,14 @@ const NG_BINDING_CLASS = 'ng-binding';
* Const of making objects: http://jsperf.com/instantiate-size-of-object * Const of making objects: http://jsperf.com/instantiate-size-of-object
*/ */
export class DomView { export class DomView {
hostLightDom: LightDom; hostLightDom: LightDom = null;
shadowRoot; shadowRoot = null;
hydrated: boolean; hydrated: boolean = false;
eventDispatcher: EventDispatcher; eventDispatcher: EventDispatcher = null;
eventHandlerRemovers: List<Function>; eventHandlerRemovers: List<Function> = [];
constructor(public proto: DomProtoView, public rootNodes: List</*node*/ any>, constructor(public proto: DomProtoView, public rootNodes: List</*node*/ any>,
public boundTextNodes: List</*node*/ any>, public boundElements: List<DomElement>) { public boundTextNodes: List</*node*/ any>, public boundElements: List<DomElement>) {}
this.hostLightDom = null;
this.hydrated = false;
this.eventHandlerRemovers = [];
this.eventDispatcher = null;
this.shadowRoot = null;
}
getDirectParentElement(boundElementIndex: number): DomElement { getDirectParentElement(boundElementIndex: number): DomElement {
var binder = this.proto.elementBinders[boundElementIndex]; var binder = this.proto.elementBinders[boundElementIndex];

View File

@ -3,12 +3,8 @@ import {ListWrapper, MapWrapper, List} from 'angular2/src/facade/collection';
import * as viewModule from './view'; import * as viewModule from './view';
export class DomViewContainer { export class DomViewContainer {
views: List<viewModule.DomView>; // The order in this list matches the DOM order.
views: List<viewModule.DomView> = [];
constructor() {
// The order in this list matches the DOM order.
this.views = [];
}
contentTagContainers() { return this.views; } contentTagContainers() { return this.views; }