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

@ -8,20 +8,13 @@ import {CompileStep} from './compile_step';
* Right now it only allows to add a parent element.
*/
export class CompileControl {
_steps: List<CompileStep>;
_currentStepIndex: number;
_parent: CompileElement;
_results;
_additionalChildren;
_currentStepIndex: number = 0;
_parent: CompileElement = null;
_results = null;
_additionalChildren = null;
_ignoreCurrentElement: boolean;
constructor(steps) {
this._steps = steps;
this._currentStepIndex = 0;
this._parent = null;
this._results = null;
this._additionalChildren = null;
}
constructor(public _steps: List<CompileStep>) {}
// only public so that it can be used by compile_pipeline
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.
*/
export class CompileElement {
element;
_attrs: Map<string, string>;
_classList: List<string>;
isViewRoot: boolean;
inheritedProtoView: ProtoViewBuilder;
distanceToInheritedBinder: number;
inheritedElementBinder: ElementBinderBuilder;
compileChildren: boolean;
_attrs: Map<string, string> = null;
_classList: List<string> = null;
isViewRoot: boolean = false;
// inherited down to children if they don't have an own protoView
inheritedProtoView: ProtoViewBuilder = null;
distanceToInheritedBinder: number = 0;
// inherited down to children if they don't have an own elementBinder
inheritedElementBinder: ElementBinderBuilder = null;
compileChildren: boolean = true;
elementDescription: string; // e.g. '<div [class]="foo">' : used to provide context in case of
// error
constructor(element, compilationUnit = '') {
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;
constructor(public element, compilationUnit: string = '') {
// description is calculated here as compilation steps may change the element
var tplDesc = assertionsEnabled() ? getElementDescription(element) : null;
if (compilationUnit !== '') {

View File

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

View File

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

View File

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

View File

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

View File

@ -15,13 +15,9 @@ import {UrlResolver} from 'angular2/src/services/url_resolver';
*/
@Injectable()
export class TemplateLoader {
_xhr: XHR;
_htmlCache: StringMap<string, /*element*/ any>;
_htmlCache: StringMap<string, /*element*/ any> = StringMapWrapper.create();
constructor(xhr: XHR, urlResolver: UrlResolver) {
this._xhr = xhr;
this._htmlCache = StringMapWrapper.create();
}
constructor(public _xhr: XHR, urlResolver: UrlResolver) {}
load(template: ViewDefinition): Promise</*element*/ any> {
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.
*/
export class TextInterpolationParser implements CompileStep {
_parser: Parser;
constructor(parser: Parser) { this._parser = parser; }
constructor(public _parser: Parser) {}
process(parent: CompileElement, current: CompileElement, control: CompileControl) {
if (!current.compileChildren) {

View File

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