chore(typing): extract abstract superclasses to replace @private constructors

This commit is contained in:
Alex Eagle
2015-10-06 06:53:39 -07:00
committed by vsavkin
parent ee32b1bc37
commit 6075509f26
65 changed files with 994 additions and 797 deletions
@@ -1,25 +1,86 @@
import {Type, isPresent, isBlank} from 'angular2/src/core/facade/lang';
import {ListWrapper, MapWrapper, Predicate} from 'angular2/src/core/facade/collection';
import {unimplemented} from 'angular2/src/core/facade/exceptions';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {ElementInjector} from 'angular2/src/core/linker/element_injector';
import {AppView} from 'angular2/src/core/linker/view';
import {internalView} from 'angular2/src/core/linker/view_ref';
import {ElementRef} from 'angular2/src/core/linker/element_ref';
import {ElementRef, ElementRef_} from 'angular2/src/core/linker/element_ref';
/**
* A DebugElement contains information from the Angular compiler about an
* element and provides access to the corresponding ElementInjector and
* underlying DOM Element, as well as a way to query for children.
*/
export class DebugElement {
_elementInjector: ElementInjector;
export abstract class DebugElement {
get componentInstance(): any { return unimplemented(); };
get nativeElement(): any { return unimplemented(); };
get elementRef(): ElementRef { return unimplemented(); };
abstract getDirectiveInstance(directiveIndex: number): any;
/**
* @internal
* Get child DebugElements from within the Light DOM.
*
* @return {DebugElement[]}
*/
get children(): DebugElement[] { return unimplemented(); };
/**
* Get the root DebugElement children of a component. Returns an empty
* list if the current DebugElement is not a component root.
*
* @return {DebugElement[]}
*/
get componentViewChildren(): DebugElement[] { return unimplemented(); };
abstract triggerEventHandler(eventName: string, eventObj: Event): void;
abstract hasDirective(type: Type): boolean;
abstract inject(type: Type): any;
abstract getLocal(name: string): any;
/**
* Return the first descendant TestElement matching the given predicate
* and scope.
*
* @param {Function: boolean} predicate
* @param {Scope} scope
*
* @return {DebugElement}
*/
query(predicate: Predicate<DebugElement>, scope: Function = Scope.all): DebugElement {
var results = this.queryAll(predicate, scope);
return results.length > 0 ? results[0] : null;
}
/**
* Return descendant TestElememts matching the given predicate
* and scope.
*
* @param {Function: boolean} predicate
* @param {Scope} scope
*
* @return {DebugElement[]}
*/
queryAll(predicate: Predicate<DebugElement>, scope: Function = Scope.all): DebugElement[] {
var elementsInScope = scope(this);
return ListWrapper.filter(elementsInScope, predicate);
}
}
export class DebugElement_ extends DebugElement {
_elementInjector: ElementInjector;
constructor(private _parentView: AppView, private _boundElementIndex: number) {
super();
this._elementInjector = this._parentView.elementInjectors[this._boundElementIndex];
}
@@ -38,21 +99,10 @@ export class DebugElement {
return this._elementInjector.getDirectiveAtIndex(directiveIndex);
}
/**
* Get child DebugElements from within the Light DOM.
*
* @return {DebugElement[]}
*/
get children(): DebugElement[] {
return this._getChildElements(this._parentView, this._boundElementIndex);
}
/**
* Get the root DebugElement children of a component. Returns an empty
* list if the current DebugElement is not a component root.
*
* @return {DebugElement[]}
*/
get componentViewChildren(): DebugElement[] {
var shadowView = this._parentView.getNestedView(this._boundElementIndex);
@@ -84,35 +134,6 @@ export class DebugElement {
getLocal(name: string): any { return this._parentView.locals.get(name); }
/**
* Return the first descendant TestElement matching the given predicate
* and scope.
*
* @param {Function: boolean} predicate
* @param {Scope} scope
*
* @return {DebugElement}
*/
query(predicate: Predicate<DebugElement>, scope: Function = Scope.all): DebugElement {
var results = this.queryAll(predicate, scope);
return results.length > 0 ? results[0] : null;
}
/**
* Return descendant TestElememts matching the given predicate
* and scope.
*
* @param {Function: boolean} predicate
* @param {Scope} scope
*
* @return {DebugElement[]}
*/
queryAll(predicate: Predicate<DebugElement>, scope: Function = Scope.all): DebugElement[] {
var elementsInScope = scope(this);
return ListWrapper.filter(elementsInScope, predicate);
}
_getChildElements(view: AppView, parentBoundElementIndex: number): DebugElement[] {
var els = [];
var parentElementBinder = null;
@@ -122,7 +143,7 @@ export class DebugElement {
for (var i = 0; i < view.proto.elementBinders.length; ++i) {
var binder = view.proto.elementBinders[i];
if (binder.parent == parentElementBinder) {
els.push(new DebugElement(view, view.elementOffset + i));
els.push(new DebugElement_(view, view.elementOffset + i));
var views = view.viewContainers[view.elementOffset + i];
if (isPresent(views)) {
@@ -142,7 +163,8 @@ export class DebugElement {
* @return {DebugElement}
*/
export function inspectElement(elementRef: ElementRef): DebugElement {
return new DebugElement(internalView(elementRef.parentView), elementRef.boundElementIndex);
return new DebugElement_(internalView((<ElementRef_>elementRef).parentView),
(<ElementRef_>elementRef).boundElementIndex);
}
export function asNativeElements(arr: DebugElement[]): any[] {
@@ -5,7 +5,7 @@ import {AppViewListener} from 'angular2/src/core/linker/view_listener';
import {AppView} from 'angular2/src/core/linker/view';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {Renderer} from 'angular2/src/core/render/api';
import {DebugElement} from './debug_element';
import {DebugElement, DebugElement_} from './debug_element';
const NG_ID_PROPERTY = 'ngid';
const INSPECT_GLOBAL_NAME = 'ng.probe';
@@ -38,7 +38,7 @@ export function inspectNativeElement(element): DebugElement {
if (isPresent(elId)) {
var view = _allViewsById.get(elId[0]);
if (isPresent(view)) {
return new DebugElement(view, elId[1]);
return new DebugElement_(view, elId[1]);
}
}
return null;