style(compiler): idiomatic TS
This commit is contained in:
@ -10,14 +10,9 @@ import 'dart:collection';
|
|||||||
* For now it uses a plain list of observable callbacks.
|
* For now it uses a plain list of observable callbacks.
|
||||||
*/
|
*/
|
||||||
class BaseQueryList<T> extends Object with IterableMixin<T> {
|
class BaseQueryList<T> extends Object with IterableMixin<T> {
|
||||||
List<T> _results;
|
List<T> _results = [];
|
||||||
List _callbacks;
|
List _callbacks = [];
|
||||||
bool _dirty;
|
bool _dirty = false;
|
||||||
|
|
||||||
BaseQueryList()
|
|
||||||
: _results = [],
|
|
||||||
_callbacks = [],
|
|
||||||
_dirty = false;
|
|
||||||
|
|
||||||
Iterator<T> get iterator => _results.iterator;
|
Iterator<T> get iterator => _results.iterator;
|
||||||
|
|
||||||
@ -40,14 +35,14 @@ class BaseQueryList<T> extends Object with IterableMixin<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onChange(callback) {
|
onChange(callback) {
|
||||||
this._callbacks.add(callback);
|
_callbacks.add(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeCallback(callback) {
|
removeCallback(callback) {
|
||||||
this._callbacks.remove(callback);
|
_callbacks.remove(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
get length => this._results.length;
|
get length => _results.length;
|
||||||
get first => this._results.first;
|
get first => _results.first;
|
||||||
get last => this._results.last;
|
get last => _results.last;
|
||||||
}
|
}
|
||||||
|
@ -10,15 +10,9 @@ import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
|
|||||||
* @exportedAs angular2/view
|
* @exportedAs angular2/view
|
||||||
*/
|
*/
|
||||||
export class BaseQueryList<T> {
|
export class BaseQueryList<T> {
|
||||||
protected _results: List<T>;
|
protected _results: List<T> = [];
|
||||||
protected _callbacks;
|
protected _callbacks = [];
|
||||||
protected _dirty;
|
protected _dirty = false;
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this._results = [];
|
|
||||||
this._callbacks = [];
|
|
||||||
this._dirty = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Symbol.iterator]() { return this._results[Symbol.iterator](); }
|
[Symbol.iterator]() { return this._results[Symbol.iterator](); }
|
||||||
|
|
||||||
|
@ -30,8 +30,7 @@ import * as renderApi from 'angular2/src/render/api';
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CompilerCache {
|
export class CompilerCache {
|
||||||
_cache: Map<Type, AppProtoView>;
|
_cache: Map<Type, AppProtoView> = MapWrapper.create();
|
||||||
constructor() { this._cache = MapWrapper.create(); }
|
|
||||||
|
|
||||||
set(component: Type, protoView: AppProtoView): void {
|
set(component: Type, protoView: AppProtoView): void {
|
||||||
MapWrapper.set(this._cache, component, protoView);
|
MapWrapper.set(this._cache, component, protoView);
|
||||||
|
@ -23,13 +23,7 @@ export class ComponentRef {
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DynamicComponentLoader {
|
export class DynamicComponentLoader {
|
||||||
private _compiler: Compiler;
|
constructor(private _compiler: Compiler, private _viewManager: AppViewManager) {}
|
||||||
private _viewManager: AppViewManager;
|
|
||||||
|
|
||||||
constructor(compiler: Compiler, viewManager: AppViewManager) {
|
|
||||||
this._compiler = compiler;
|
|
||||||
this._viewManager = viewManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a component into the location given by the provided ElementRef. The loaded component
|
* Loads a component into the location given by the provided ElementRef. The loaded component
|
||||||
@ -53,7 +47,7 @@ export class DynamicComponentLoader {
|
|||||||
* component's selector.
|
* component's selector.
|
||||||
* The loaded component receives injection normally as a hosted view.
|
* The loaded component receives injection normally as a hosted view.
|
||||||
*/
|
*/
|
||||||
loadAsRoot(typeOrBinding, overrideSelector = null,
|
loadAsRoot(typeOrBinding, overrideSelector: string = null,
|
||||||
injector: Injector = null): Promise<ComponentRef> {
|
injector: Injector = null): Promise<ComponentRef> {
|
||||||
return this._compiler.compileInHost(this._getBinding(typeOrBinding))
|
return this._compiler.compileInHost(this._getBinding(typeOrBinding))
|
||||||
.then(hostProtoViewRef => {
|
.then(hostProtoViewRef => {
|
||||||
|
@ -6,8 +6,10 @@ import {List, StringMap} from 'angular2/src/facade/collection';
|
|||||||
import * as viewModule from './view';
|
import * as viewModule from './view';
|
||||||
|
|
||||||
export class ElementBinder {
|
export class ElementBinder {
|
||||||
nestedProtoView: viewModule.AppProtoView;
|
// updated later when events are bound
|
||||||
hostListeners: StringMap<string, Map<number, AST>>;
|
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,
|
constructor(public index: int, public parent: ElementBinder, public distanceToParent: int,
|
||||||
public protoElementInjector: eiModule.ProtoElementInjector,
|
public protoElementInjector: eiModule.ProtoElementInjector,
|
||||||
@ -16,10 +18,6 @@ export class ElementBinder {
|
|||||||
if (isBlank(index)) {
|
if (isBlank(index)) {
|
||||||
throw new BaseException('null index not allowed.');
|
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() {
|
hasStaticComponent() {
|
||||||
|
@ -7,13 +7,7 @@ import {resolveInternalDomView} from 'angular2/src/render/dom/view/view';
|
|||||||
* @exportedAs angular2/view
|
* @exportedAs angular2/view
|
||||||
*/
|
*/
|
||||||
export class ElementRef {
|
export class ElementRef {
|
||||||
parentView: ViewRef;
|
constructor(public parentView: ViewRef, public boundElementIndex: number) {}
|
||||||
boundElementIndex: number;
|
|
||||||
|
|
||||||
constructor(parentView: ViewRef, boundElementIndex: number) {
|
|
||||||
this.parentView = parentView;
|
|
||||||
this.boundElementIndex = boundElementIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exposes the underlying DOM element.
|
* Exposes the underlying DOM element.
|
||||||
|
@ -20,13 +20,8 @@ import {ElementBinder} from './element_binder';
|
|||||||
import {ProtoElementInjector, DirectiveBinding} from './element_injector';
|
import {ProtoElementInjector, DirectiveBinding} from './element_injector';
|
||||||
|
|
||||||
class BindingRecordsCreator {
|
class BindingRecordsCreator {
|
||||||
_directiveRecordsMap: Map<number, DirectiveRecord>;
|
_directiveRecordsMap: Map<number, DirectiveRecord> = MapWrapper.create();
|
||||||
_textNodeIndex: number;
|
_textNodeIndex: number = 0;
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this._directiveRecordsMap = MapWrapper.create();
|
|
||||||
this._textNodeIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
getBindingRecords(elementBinders: List<renderApi.ElementBinder>,
|
getBindingRecords(elementBinders: List<renderApi.ElementBinder>,
|
||||||
allDirectiveMetadatas: List<renderApi.DirectiveMetadata>): List<BindingRecord> {
|
allDirectiveMetadatas: List<renderApi.DirectiveMetadata>): List<BindingRecord> {
|
||||||
@ -139,9 +134,7 @@ class BindingRecordsCreator {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ProtoViewFactory {
|
export class ProtoViewFactory {
|
||||||
_changeDetection: ChangeDetection;
|
constructor(public _changeDetection: ChangeDetection) {}
|
||||||
|
|
||||||
constructor(changeDetection: ChangeDetection) { this._changeDetection = changeDetection; }
|
|
||||||
|
|
||||||
createAppProtoViews(hostComponentBinding: DirectiveBinding,
|
createAppProtoViews(hostComponentBinding: DirectiveBinding,
|
||||||
rootRenderProtoView: renderApi.ProtoViewDto,
|
rootRenderProtoView: renderApi.ProtoViewDto,
|
||||||
@ -432,24 +425,10 @@ function _bindDirectiveEvents(protoView, elementBinders: List<renderApi.ElementB
|
|||||||
|
|
||||||
|
|
||||||
class RenderProtoViewWithIndex {
|
class RenderProtoViewWithIndex {
|
||||||
renderProtoView: renderApi.ProtoViewDto;
|
constructor(public renderProtoView: renderApi.ProtoViewDto, public index: number,
|
||||||
index: number;
|
public parentIndex: number, public boundElementIndex: 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ParentProtoElementInjectorWithDistance {
|
class ParentProtoElementInjectorWithDistance {
|
||||||
protoElementInjector: ProtoElementInjector;
|
constructor(public protoElementInjector: ProtoElementInjector, public distance: number) {}
|
||||||
distance: number;
|
|
||||||
constructor(protoElementInjector: ProtoElementInjector, distance: number) {
|
|
||||||
this.protoElementInjector = protoElementInjector;
|
|
||||||
this.distance = distance;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,7 @@ import {reflector} from 'angular2/src/reflection/reflection';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TemplateResolver {
|
export class TemplateResolver {
|
||||||
_cache: Map<Type, /*node*/ any>;
|
_cache: Map<Type, /*node*/ any> = MapWrapper.create();
|
||||||
|
|
||||||
constructor() { this._cache = MapWrapper.create(); }
|
|
||||||
|
|
||||||
resolve(component: Type): View {
|
resolve(component: Type): View {
|
||||||
var view = MapWrapper.get(this._cache, component);
|
var view = MapWrapper.get(this._cache, component);
|
||||||
|
@ -33,24 +33,24 @@ export class AppViewContainer {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class AppView implements ChangeDispatcher, EventDispatcher {
|
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
|
/// This list matches the _nodes list. It is sparse, since only Elements have ElementInjector
|
||||||
rootElementInjectors: List<ElementInjector>;
|
rootElementInjectors: List<ElementInjector>;
|
||||||
elementInjectors: List<ElementInjector>;
|
elementInjectors: List<ElementInjector> = null;
|
||||||
changeDetector: ChangeDetector;
|
changeDetector: ChangeDetector = null;
|
||||||
componentChildViews: List<AppView>;
|
componentChildViews: List<AppView> = null;
|
||||||
/// Host views that were added by an imperative view.
|
/// Host views that were added by an imperative view.
|
||||||
/// This is a dynamically growing / shrinking array.
|
/// This is a dynamically growing / shrinking array.
|
||||||
freeHostViews: List<AppView>;
|
freeHostViews: List<AppView> = [];
|
||||||
viewContainers: List<AppViewContainer>;
|
viewContainers: List<AppViewContainer>;
|
||||||
preBuiltObjects: List<PreBuiltObjects>;
|
preBuiltObjects: List<PreBuiltObjects> = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The context against which data-binding expressions in this view are evaluated against.
|
* The context against which data-binding expressions in this view are evaluated against.
|
||||||
* This is always a component instance.
|
* 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
|
* 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,
|
constructor(public renderer: renderApi.Renderer, public proto: AppProtoView,
|
||||||
protoLocals: Map<string, any>) {
|
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.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.locals = new Locals(null, MapWrapper.clone(protoLocals)); // TODO optimize this
|
||||||
this.freeHostViews = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init(changeDetector: ChangeDetector, elementInjectors: List<ElementInjector>,
|
init(changeDetector: ChangeDetector, elementInjectors: List<ElementInjector>,
|
||||||
@ -166,14 +158,12 @@ export class AppView implements ChangeDispatcher, EventDispatcher {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class AppProtoView {
|
export class AppProtoView {
|
||||||
elementBinders: List<ElementBinder>;
|
elementBinders: List<ElementBinder> = [];
|
||||||
protoLocals: Map<string, any>;
|
protoLocals: Map<string, any> = MapWrapper.create();
|
||||||
|
|
||||||
constructor(public render: renderApi.RenderProtoViewRef,
|
constructor(public render: renderApi.RenderProtoViewRef,
|
||||||
public protoChangeDetector: ProtoChangeDetector,
|
public protoChangeDetector: ProtoChangeDetector,
|
||||||
public variableBindings: Map<string, string>) {
|
public variableBindings: Map<string, string>) {
|
||||||
this.elementBinders = [];
|
|
||||||
this.protoLocals = MapWrapper.create();
|
|
||||||
if (isPresent(variableBindings)) {
|
if (isPresent(variableBindings)) {
|
||||||
MapWrapper.forEach(variableBindings, (templateName, _) => {
|
MapWrapper.forEach(variableBindings, (templateName, _) => {
|
||||||
MapWrapper.set(this.protoLocals, templateName, null);
|
MapWrapper.set(this.protoLocals, templateName, null);
|
||||||
|
@ -26,7 +26,7 @@ export class ViewContainerRef {
|
|||||||
|
|
||||||
get(index: number): ViewRef { return new ViewRef(this._getViews()[index]); }
|
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
|
// TODO(rado): profile and decide whether bounds checks should be added
|
||||||
// to the methods below.
|
// to the methods below.
|
||||||
|
@ -16,18 +16,8 @@ import {AppViewListener} from './view_listener';
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppViewManager {
|
export class AppViewManager {
|
||||||
_viewPool: AppViewPool;
|
constructor(public _viewPool: AppViewPool, public _viewListener: AppViewListener,
|
||||||
_viewListener: AppViewListener;
|
public _utils: AppViewManagerUtils, public _renderer: Renderer) {}
|
||||||
_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
getComponentView(hostLocation: ElementRef): ViewRef {
|
getComponentView(hostLocation: ElementRef): ViewRef {
|
||||||
var hostView = internalView(hostLocation.parentView);
|
var hostView = internalView(hostLocation.parentView);
|
||||||
|
@ -11,9 +11,7 @@ import {RenderViewRef} from 'angular2/src/render/api';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppViewManagerUtils {
|
export class AppViewManagerUtils {
|
||||||
_directiveResolver: DirectiveResolver;
|
constructor(public _directiveResolver: DirectiveResolver) {}
|
||||||
|
|
||||||
constructor(metadataReader: DirectiveResolver) { this._directiveResolver = metadataReader; }
|
|
||||||
|
|
||||||
getComponentInstance(parentView: viewModule.AppView, boundElementIndex: number): any {
|
getComponentInstance(parentView: viewModule.AppView, boundElementIndex: number): any {
|
||||||
var binder = parentView.proto.elementBinders[boundElementIndex];
|
var binder = parentView.proto.elementBinders[boundElementIndex];
|
||||||
|
@ -10,11 +10,11 @@ export const APP_VIEW_POOL_CAPACITY = CONST_EXPR(new OpaqueToken('AppViewPool.vi
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppViewPool {
|
export class AppViewPool {
|
||||||
_poolCapacityPerProtoView: number;
|
_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) {
|
constructor(@Inject(APP_VIEW_POOL_CAPACITY) poolCapacityPerProtoView) {
|
||||||
this._poolCapacityPerProtoView = poolCapacityPerProtoView;
|
this._poolCapacityPerProtoView = poolCapacityPerProtoView;
|
||||||
this._pooledViewsPerProtoView = MapWrapper.create();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getView(protoView: viewModule.AppProtoView): viewModule.AppView {
|
getView(protoView: viewModule.AppProtoView): viewModule.AppView {
|
||||||
|
@ -16,9 +16,7 @@ export function internalProtoView(protoViewRef: ProtoViewRef): viewModule.AppPro
|
|||||||
* @exportedAs angular2/view
|
* @exportedAs angular2/view
|
||||||
*/
|
*/
|
||||||
export class ViewRef {
|
export class ViewRef {
|
||||||
_view: viewModule.AppView;
|
constructor(public _view: viewModule.AppView) {}
|
||||||
|
|
||||||
constructor(view: viewModule.AppView) { this._view = view; }
|
|
||||||
|
|
||||||
get render(): RenderViewRef { return this._view.render; }
|
get render(): RenderViewRef { return this._view.render; }
|
||||||
|
|
||||||
@ -29,7 +27,5 @@ export class ViewRef {
|
|||||||
* @exportedAs angular2/view
|
* @exportedAs angular2/view
|
||||||
*/
|
*/
|
||||||
export class ProtoViewRef {
|
export class ProtoViewRef {
|
||||||
_protoView: viewModule.AppProtoView;
|
constructor(public _protoView: viewModule.AppProtoView) {}
|
||||||
|
|
||||||
constructor(protoView) { this._protoView = protoView; }
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user