style(compiler): idiomatic TS

This commit is contained in:
Victor Berchet 2015-06-12 22:38:44 +02:00
parent c3ae34f066
commit cebf69933c
14 changed files with 43 additions and 118 deletions

View File

@ -10,14 +10,9 @@ import 'dart:collection';
* For now it uses a plain list of observable callbacks.
*/
class BaseQueryList<T> extends Object with IterableMixin<T> {
List<T> _results;
List _callbacks;
bool _dirty;
BaseQueryList()
: _results = [],
_callbacks = [],
_dirty = false;
List<T> _results = [];
List _callbacks = [];
bool _dirty = false;
Iterator<T> get iterator => _results.iterator;
@ -40,14 +35,14 @@ class BaseQueryList<T> extends Object with IterableMixin<T> {
}
onChange(callback) {
this._callbacks.add(callback);
_callbacks.add(callback);
}
removeCallback(callback) {
this._callbacks.remove(callback);
_callbacks.remove(callback);
}
get length => this._results.length;
get first => this._results.first;
get last => this._results.last;
get length => _results.length;
get first => _results.first;
get last => _results.last;
}

View File

@ -10,15 +10,9 @@ import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
* @exportedAs angular2/view
*/
export class BaseQueryList<T> {
protected _results: List<T>;
protected _callbacks;
protected _dirty;
constructor() {
this._results = [];
this._callbacks = [];
this._dirty = false;
}
protected _results: List<T> = [];
protected _callbacks = [];
protected _dirty = false;
[Symbol.iterator]() { return this._results[Symbol.iterator](); }

View File

@ -30,8 +30,7 @@ import * as renderApi from 'angular2/src/render/api';
*/
@Injectable()
export class CompilerCache {
_cache: Map<Type, AppProtoView>;
constructor() { this._cache = MapWrapper.create(); }
_cache: Map<Type, AppProtoView> = MapWrapper.create();
set(component: Type, protoView: AppProtoView): void {
MapWrapper.set(this._cache, component, protoView);

View File

@ -23,13 +23,7 @@ export class ComponentRef {
*/
@Injectable()
export class DynamicComponentLoader {
private _compiler: Compiler;
private _viewManager: AppViewManager;
constructor(compiler: Compiler, viewManager: AppViewManager) {
this._compiler = compiler;
this._viewManager = viewManager;
}
constructor(private _compiler: Compiler, private _viewManager: AppViewManager) {}
/**
* Loads a component into the location given by the provided ElementRef. The loaded component
@ -53,7 +47,7 @@ export class DynamicComponentLoader {
* component's selector.
* The loaded component receives injection normally as a hosted view.
*/
loadAsRoot(typeOrBinding, overrideSelector = null,
loadAsRoot(typeOrBinding, overrideSelector: string = null,
injector: Injector = null): Promise<ComponentRef> {
return this._compiler.compileInHost(this._getBinding(typeOrBinding))
.then(hostProtoViewRef => {

View File

@ -6,8 +6,10 @@ import {List, StringMap} from 'angular2/src/facade/collection';
import * as viewModule from './view';
export class ElementBinder {
nestedProtoView: viewModule.AppProtoView;
hostListeners: StringMap<string, Map<number, AST>>;
// updated later when events are bound
nestedProtoView: viewModule.AppProtoView = null;
// updated later, so we are able to resolve cycles
hostListeners: StringMap<string, Map<number, AST>> = null;
constructor(public index: int, public parent: ElementBinder, public distanceToParent: int,
public protoElementInjector: eiModule.ProtoElementInjector,
@ -16,10 +18,6 @@ export class ElementBinder {
if (isBlank(index)) {
throw new BaseException('null index not allowed.');
}
// updated later when events are bound
this.hostListeners = null;
// updated later, so we are able to resolve cycles
this.nestedProtoView = null;
}
hasStaticComponent() {

View File

@ -7,13 +7,7 @@ import {resolveInternalDomView} from 'angular2/src/render/dom/view/view';
* @exportedAs angular2/view
*/
export class ElementRef {
parentView: ViewRef;
boundElementIndex: number;
constructor(parentView: ViewRef, boundElementIndex: number) {
this.parentView = parentView;
this.boundElementIndex = boundElementIndex;
}
constructor(public parentView: ViewRef, public boundElementIndex: number) {}
/**
* Exposes the underlying DOM element.

View File

@ -20,13 +20,8 @@ import {ElementBinder} from './element_binder';
import {ProtoElementInjector, DirectiveBinding} from './element_injector';
class BindingRecordsCreator {
_directiveRecordsMap: Map<number, DirectiveRecord>;
_textNodeIndex: number;
constructor() {
this._directiveRecordsMap = MapWrapper.create();
this._textNodeIndex = 0;
}
_directiveRecordsMap: Map<number, DirectiveRecord> = MapWrapper.create();
_textNodeIndex: number = 0;
getBindingRecords(elementBinders: List<renderApi.ElementBinder>,
allDirectiveMetadatas: List<renderApi.DirectiveMetadata>): List<BindingRecord> {
@ -139,9 +134,7 @@ class BindingRecordsCreator {
@Injectable()
export class ProtoViewFactory {
_changeDetection: ChangeDetection;
constructor(changeDetection: ChangeDetection) { this._changeDetection = changeDetection; }
constructor(public _changeDetection: ChangeDetection) {}
createAppProtoViews(hostComponentBinding: DirectiveBinding,
rootRenderProtoView: renderApi.ProtoViewDto,
@ -432,24 +425,10 @@ function _bindDirectiveEvents(protoView, elementBinders: List<renderApi.ElementB
class RenderProtoViewWithIndex {
renderProtoView: renderApi.ProtoViewDto;
index: number;
parentIndex: number;
boundElementIndex: number;
constructor(renderProtoView: renderApi.ProtoViewDto, index: number, parentIndex: number,
boundElementIndex: number) {
this.renderProtoView = renderProtoView;
this.index = index;
this.parentIndex = parentIndex;
this.boundElementIndex = boundElementIndex;
}
constructor(public renderProtoView: renderApi.ProtoViewDto, public index: number,
public parentIndex: number, public boundElementIndex: number) {}
}
class ParentProtoElementInjectorWithDistance {
protoElementInjector: ProtoElementInjector;
distance: number;
constructor(protoElementInjector: ProtoElementInjector, distance: number) {
this.protoElementInjector = protoElementInjector;
this.distance = distance;
}
constructor(public protoElementInjector: ProtoElementInjector, public distance: number) {}
}

View File

@ -9,9 +9,7 @@ import {reflector} from 'angular2/src/reflection/reflection';
@Injectable()
export class TemplateResolver {
_cache: Map<Type, /*node*/ any>;
constructor() { this._cache = MapWrapper.create(); }
_cache: Map<Type, /*node*/ any> = MapWrapper.create();
resolve(component: Type): View {
var view = MapWrapper.get(this._cache, component);

View File

@ -33,24 +33,24 @@ export class AppViewContainer {
*
*/
export class AppView implements ChangeDispatcher, EventDispatcher {
render: renderApi.RenderViewRef;
render: renderApi.RenderViewRef = null;
/// This list matches the _nodes list. It is sparse, since only Elements have ElementInjector
rootElementInjectors: List<ElementInjector>;
elementInjectors: List<ElementInjector>;
changeDetector: ChangeDetector;
componentChildViews: List<AppView>;
elementInjectors: List<ElementInjector> = null;
changeDetector: ChangeDetector = null;
componentChildViews: List<AppView> = null;
/// Host views that were added by an imperative view.
/// This is a dynamically growing / shrinking array.
freeHostViews: List<AppView>;
freeHostViews: List<AppView> = [];
viewContainers: List<AppViewContainer>;
preBuiltObjects: List<PreBuiltObjects>;
preBuiltObjects: List<PreBuiltObjects> = null;
/**
* The context against which data-binding expressions in this view are evaluated against.
* This is always a component instance.
*/
context: any;
context: any = null;
/**
* Variables, local to this view, that can be used in binding expressions (in addition to the
@ -61,16 +61,8 @@ export class AppView implements ChangeDispatcher, EventDispatcher {
constructor(public renderer: renderApi.Renderer, public proto: AppProtoView,
protoLocals: Map<string, any>) {
this.render = null;
this.changeDetector = null;
this.elementInjectors = null;
this.rootElementInjectors = null;
this.componentChildViews = null;
this.viewContainers = ListWrapper.createFixedSize(this.proto.elementBinders.length);
this.preBuiltObjects = null;
this.context = null;
this.locals = new Locals(null, MapWrapper.clone(protoLocals)); // TODO optimize this
this.freeHostViews = [];
}
init(changeDetector: ChangeDetector, elementInjectors: List<ElementInjector>,
@ -166,14 +158,12 @@ export class AppView implements ChangeDispatcher, EventDispatcher {
*
*/
export class AppProtoView {
elementBinders: List<ElementBinder>;
protoLocals: Map<string, any>;
elementBinders: List<ElementBinder> = [];
protoLocals: Map<string, any> = MapWrapper.create();
constructor(public render: renderApi.RenderProtoViewRef,
public protoChangeDetector: ProtoChangeDetector,
public variableBindings: Map<string, string>) {
this.elementBinders = [];
this.protoLocals = MapWrapper.create();
if (isPresent(variableBindings)) {
MapWrapper.forEach(variableBindings, (templateName, _) => {
MapWrapper.set(this.protoLocals, templateName, null);

View File

@ -26,7 +26,7 @@ export class ViewContainerRef {
get(index: number): ViewRef { return new ViewRef(this._getViews()[index]); }
get length() /* :int */ { return this._getViews().length; }
get length(): number { return this._getViews().length; }
// TODO(rado): profile and decide whether bounds checks should be added
// to the methods below.

View File

@ -16,18 +16,8 @@ import {AppViewListener} from './view_listener';
*/
@Injectable()
export class AppViewManager {
_viewPool: AppViewPool;
_viewListener: AppViewListener;
_utils: AppViewManagerUtils;
_renderer: Renderer;
constructor(viewPool: AppViewPool, viewListener: AppViewListener, utils: AppViewManagerUtils,
renderer: Renderer) {
this._viewPool = viewPool;
this._viewListener = viewListener;
this._utils = utils;
this._renderer = renderer;
}
constructor(public _viewPool: AppViewPool, public _viewListener: AppViewListener,
public _utils: AppViewManagerUtils, public _renderer: Renderer) {}
getComponentView(hostLocation: ElementRef): ViewRef {
var hostView = internalView(hostLocation.parentView);

View File

@ -11,9 +11,7 @@ import {RenderViewRef} from 'angular2/src/render/api';
@Injectable()
export class AppViewManagerUtils {
_directiveResolver: DirectiveResolver;
constructor(metadataReader: DirectiveResolver) { this._directiveResolver = metadataReader; }
constructor(public _directiveResolver: DirectiveResolver) {}
getComponentInstance(parentView: viewModule.AppView, boundElementIndex: number): any {
var binder = parentView.proto.elementBinders[boundElementIndex];

View File

@ -10,11 +10,11 @@ export const APP_VIEW_POOL_CAPACITY = CONST_EXPR(new OpaqueToken('AppViewPool.vi
@Injectable()
export class AppViewPool {
_poolCapacityPerProtoView: number;
_pooledViewsPerProtoView: Map<viewModule.AppProtoView, List<viewModule.AppView>>;
_pooledViewsPerProtoView: Map<viewModule.AppProtoView, List<viewModule.AppView>> =
MapWrapper.create();
constructor(@Inject(APP_VIEW_POOL_CAPACITY) poolCapacityPerProtoView) {
this._poolCapacityPerProtoView = poolCapacityPerProtoView;
this._pooledViewsPerProtoView = MapWrapper.create();
}
getView(protoView: viewModule.AppProtoView): viewModule.AppView {

View File

@ -16,9 +16,7 @@ export function internalProtoView(protoViewRef: ProtoViewRef): viewModule.AppPro
* @exportedAs angular2/view
*/
export class ViewRef {
_view: viewModule.AppView;
constructor(view: viewModule.AppView) { this._view = view; }
constructor(public _view: viewModule.AppView) {}
get render(): RenderViewRef { return this._view.render; }
@ -29,7 +27,5 @@ export class ViewRef {
* @exportedAs angular2/view
*/
export class ProtoViewRef {
_protoView: viewModule.AppProtoView;
constructor(protoView) { this._protoView = protoView; }
constructor(public _protoView: viewModule.AppProtoView) {}
}