diff --git a/modules/angular2/src/core/compiler/base_query_list.dart b/modules/angular2/src/core/compiler/base_query_list.dart index 6c38e44d13..1b1d53bc74 100644 --- a/modules/angular2/src/core/compiler/base_query_list.dart +++ b/modules/angular2/src/core/compiler/base_query_list.dart @@ -10,14 +10,9 @@ import 'dart:collection'; * For now it uses a plain list of observable callbacks. */ class BaseQueryList extends Object with IterableMixin { - List _results; - List _callbacks; - bool _dirty; - - BaseQueryList() - : _results = [], - _callbacks = [], - _dirty = false; + List _results = []; + List _callbacks = []; + bool _dirty = false; Iterator get iterator => _results.iterator; @@ -40,14 +35,14 @@ class BaseQueryList extends Object with IterableMixin { } 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; } diff --git a/modules/angular2/src/core/compiler/base_query_list.ts b/modules/angular2/src/core/compiler/base_query_list.ts index e87c07a014..212d0c3414 100644 --- a/modules/angular2/src/core/compiler/base_query_list.ts +++ b/modules/angular2/src/core/compiler/base_query_list.ts @@ -10,15 +10,9 @@ import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection'; * @exportedAs angular2/view */ export class BaseQueryList { - protected _results: List; - protected _callbacks; - protected _dirty; - - constructor() { - this._results = []; - this._callbacks = []; - this._dirty = false; - } + protected _results: List = []; + protected _callbacks = []; + protected _dirty = false; [Symbol.iterator]() { return this._results[Symbol.iterator](); } diff --git a/modules/angular2/src/core/compiler/compiler.ts b/modules/angular2/src/core/compiler/compiler.ts index 4305c2693e..2d60a6ca0a 100644 --- a/modules/angular2/src/core/compiler/compiler.ts +++ b/modules/angular2/src/core/compiler/compiler.ts @@ -30,8 +30,7 @@ import * as renderApi from 'angular2/src/render/api'; */ @Injectable() export class CompilerCache { - _cache: Map; - constructor() { this._cache = MapWrapper.create(); } + _cache: Map = MapWrapper.create(); set(component: Type, protoView: AppProtoView): void { MapWrapper.set(this._cache, component, protoView); diff --git a/modules/angular2/src/core/compiler/dynamic_component_loader.ts b/modules/angular2/src/core/compiler/dynamic_component_loader.ts index e71119a064..eb8a798b8b 100644 --- a/modules/angular2/src/core/compiler/dynamic_component_loader.ts +++ b/modules/angular2/src/core/compiler/dynamic_component_loader.ts @@ -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 { return this._compiler.compileInHost(this._getBinding(typeOrBinding)) .then(hostProtoViewRef => { diff --git a/modules/angular2/src/core/compiler/element_binder.ts b/modules/angular2/src/core/compiler/element_binder.ts index 9e629de41a..0e25abdfa6 100644 --- a/modules/angular2/src/core/compiler/element_binder.ts +++ b/modules/angular2/src/core/compiler/element_binder.ts @@ -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>; + // updated later when events are bound + nestedProtoView: viewModule.AppProtoView = null; + // updated later, so we are able to resolve cycles + hostListeners: StringMap> = 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() { diff --git a/modules/angular2/src/core/compiler/element_ref.ts b/modules/angular2/src/core/compiler/element_ref.ts index 593f88f160..83e60c969a 100644 --- a/modules/angular2/src/core/compiler/element_ref.ts +++ b/modules/angular2/src/core/compiler/element_ref.ts @@ -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. diff --git a/modules/angular2/src/core/compiler/proto_view_factory.ts b/modules/angular2/src/core/compiler/proto_view_factory.ts index 12312c3d98..38d7f0d795 100644 --- a/modules/angular2/src/core/compiler/proto_view_factory.ts +++ b/modules/angular2/src/core/compiler/proto_view_factory.ts @@ -20,13 +20,8 @@ import {ElementBinder} from './element_binder'; import {ProtoElementInjector, DirectiveBinding} from './element_injector'; class BindingRecordsCreator { - _directiveRecordsMap: Map; - _textNodeIndex: number; - - constructor() { - this._directiveRecordsMap = MapWrapper.create(); - this._textNodeIndex = 0; - } + _directiveRecordsMap: Map = MapWrapper.create(); + _textNodeIndex: number = 0; getBindingRecords(elementBinders: List, allDirectiveMetadatas: List): List { @@ -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; - - constructor() { this._cache = MapWrapper.create(); } + _cache: Map = MapWrapper.create(); resolve(component: Type): View { var view = MapWrapper.get(this._cache, component); diff --git a/modules/angular2/src/core/compiler/view.ts b/modules/angular2/src/core/compiler/view.ts index 2b383f40ed..ef1dec150e 100644 --- a/modules/angular2/src/core/compiler/view.ts +++ b/modules/angular2/src/core/compiler/view.ts @@ -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; - elementInjectors: List; - changeDetector: ChangeDetector; - componentChildViews: List; + elementInjectors: List = null; + changeDetector: ChangeDetector = null; + componentChildViews: List = null; /// Host views that were added by an imperative view. /// This is a dynamically growing / shrinking array. - freeHostViews: List; + freeHostViews: List = []; viewContainers: List; - preBuiltObjects: List; + preBuiltObjects: List = 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) { - 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, @@ -166,14 +158,12 @@ export class AppView implements ChangeDispatcher, EventDispatcher { * */ export class AppProtoView { - elementBinders: List; - protoLocals: Map; + elementBinders: List = []; + protoLocals: Map = MapWrapper.create(); constructor(public render: renderApi.RenderProtoViewRef, public protoChangeDetector: ProtoChangeDetector, public variableBindings: Map) { - this.elementBinders = []; - this.protoLocals = MapWrapper.create(); if (isPresent(variableBindings)) { MapWrapper.forEach(variableBindings, (templateName, _) => { MapWrapper.set(this.protoLocals, templateName, null); diff --git a/modules/angular2/src/core/compiler/view_container_ref.ts b/modules/angular2/src/core/compiler/view_container_ref.ts index 3373656bdc..36e723fb7d 100644 --- a/modules/angular2/src/core/compiler/view_container_ref.ts +++ b/modules/angular2/src/core/compiler/view_container_ref.ts @@ -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. diff --git a/modules/angular2/src/core/compiler/view_manager.ts b/modules/angular2/src/core/compiler/view_manager.ts index d4c28894fc..ec5213fb73 100644 --- a/modules/angular2/src/core/compiler/view_manager.ts +++ b/modules/angular2/src/core/compiler/view_manager.ts @@ -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); diff --git a/modules/angular2/src/core/compiler/view_manager_utils.ts b/modules/angular2/src/core/compiler/view_manager_utils.ts index 46cf5720f0..52031e1105 100644 --- a/modules/angular2/src/core/compiler/view_manager_utils.ts +++ b/modules/angular2/src/core/compiler/view_manager_utils.ts @@ -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]; diff --git a/modules/angular2/src/core/compiler/view_pool.ts b/modules/angular2/src/core/compiler/view_pool.ts index 035617b008..667ddb22c6 100644 --- a/modules/angular2/src/core/compiler/view_pool.ts +++ b/modules/angular2/src/core/compiler/view_pool.ts @@ -10,11 +10,11 @@ export const APP_VIEW_POOL_CAPACITY = CONST_EXPR(new OpaqueToken('AppViewPool.vi @Injectable() export class AppViewPool { _poolCapacityPerProtoView: number; - _pooledViewsPerProtoView: Map>; + _pooledViewsPerProtoView: Map> = + MapWrapper.create(); constructor(@Inject(APP_VIEW_POOL_CAPACITY) poolCapacityPerProtoView) { this._poolCapacityPerProtoView = poolCapacityPerProtoView; - this._pooledViewsPerProtoView = MapWrapper.create(); } getView(protoView: viewModule.AppProtoView): viewModule.AppView { diff --git a/modules/angular2/src/core/compiler/view_ref.ts b/modules/angular2/src/core/compiler/view_ref.ts index 13ffd12149..19263e607a 100644 --- a/modules/angular2/src/core/compiler/view_ref.ts +++ b/modules/angular2/src/core/compiler/view_ref.ts @@ -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) {} }