chore: add more type annotations

This commit is contained in:
Kevin Moore
2015-04-19 14:47:02 -07:00
parent e23004df52
commit f7f06c5ad4
17 changed files with 80 additions and 81 deletions

View File

@ -38,14 +38,14 @@ export class View {
*
* NOTE: either `templateURL` or `template` should be used, but not both.
*/
templateUrl:any; //string;
templateUrl:string;
/**
* Specifies an inline template for an angular component.
*
* NOTE: either `templateURL` or `template` should be used, but not both.
*/
template:any; //string;
template:string;
/**
* Specifies a list of directives that can be used within a template.
@ -69,7 +69,7 @@ export class View {
* }
* ```
*/
directives:any; //List<Type>;
directives:List<Type>;
/**
* Specify a custom renderer for this View.

View File

@ -1,7 +1,7 @@
import {OpaqueToken} from 'angular2/di';
export var appComponentRefToken = new OpaqueToken('ComponentRef');
export var appChangeDetectorToken = new OpaqueToken('AppChangeDetector');
export var appElementToken = new OpaqueToken('AppElement');
export var appComponentAnnotatedTypeToken = new OpaqueToken('AppComponentAnnotatedType');
export var appDocumentToken = new OpaqueToken('AppDocument');
export var appComponentRefToken:OpaqueToken = new OpaqueToken('ComponentRef');
export var appChangeDetectorToken:OpaqueToken = new OpaqueToken('AppChangeDetector');
export var appElementToken:OpaqueToken = new OpaqueToken('AppElement');
export var appComponentAnnotatedTypeToken:OpaqueToken = new OpaqueToken('AppComponentAnnotatedType');
export var appDocumentToken:OpaqueToken = new OpaqueToken('AppDocument');

View File

@ -26,7 +26,7 @@ export class CompilerCache {
this._cache = MapWrapper.create();
}
set(component:Type, protoView:AppProtoView) {
set(component:Type, protoView:AppProtoView):void {
MapWrapper.set(this._cache, component, protoView);
}
@ -35,7 +35,7 @@ export class CompilerCache {
return normalizeBlank(result);
}
clear() {
clear():void {
MapWrapper.clear(this._cache);
}
}
@ -73,7 +73,7 @@ export class Compiler {
this._protoViewFactory = protoViewFactory;
}
_bindDirective(directiveTypeOrBinding) {
_bindDirective(directiveTypeOrBinding):DirectiveBinding {
if (directiveTypeOrBinding instanceof DirectiveBinding) {
return directiveTypeOrBinding;
}
@ -190,7 +190,7 @@ export class Compiler {
}
}
_buildRenderTemplate(component, view, directives) {
_buildRenderTemplate(component, view, directives): renderApi.ViewDefinition {
var componentUrl = this._urlResolver.resolve(
this._appUrl, this._componentUrlMapper.getUrl(component)
);
@ -211,7 +211,7 @@ export class Compiler {
});
}
static buildRenderDirective(directiveBinding) {
static buildRenderDirective(directiveBinding):renderApi.DirectiveMetadata {
var ann = directiveBinding.annotation;
var renderType;
var compileChildren = true;
@ -254,7 +254,7 @@ export class Compiler {
return directives;
}
_flattenList(tree:List<any>, out:List<Type>) {
_flattenList(tree:List<any>, out:List<Type>):void {
for (var i = 0; i < tree.length; i++) {
var item = tree[i];
if (ListWrapper.isList(item)) {

View File

@ -123,7 +123,7 @@ export class DynamicComponentLoader {
}
/** Asserts that the type being dynamically instantiated is a Component. */
_assertTypeIsComponent(type:Type) {
_assertTypeIsComponent(type:Type):void {
var annotation = this._directiveMetadataReader.read(type).annotation;
if (!(annotation instanceof Component)) {
throw new BaseException(`Could not load '${stringify(type)}' because it is not a component.`);

View File

@ -59,7 +59,7 @@ class StaticKeys {
this.elementRefId = Key.get(ElementRef).id;
}
static instance() {
static instance():StaticKeys {
if (isBlank(_staticKeys)) _staticKeys = new StaticKeys();
return _staticKeys;
}
@ -77,17 +77,17 @@ export class TreeNode {
if (isPresent(parent)) parent.addChild(this);
}
_assertConsistency() {
_assertConsistency():void {
this._assertHeadBeforeTail();
this._assertTailReachable();
this._assertPresentInParentList();
}
_assertHeadBeforeTail() {
_assertHeadBeforeTail():void {
if (isBlank(this._tail) && isPresent(this._head)) throw new BaseException('null tail but non-null head');
}
_assertTailReachable() {
_assertTailReachable():void {
if (isBlank(this._tail)) return;
if (isPresent(this._tail._next)) throw new BaseException('node after tail');
var p = this._head;
@ -95,7 +95,7 @@ export class TreeNode {
if (isBlank(p) && isPresent(this._tail)) throw new BaseException('tail not reachable.')
}
_assertPresentInParentList() {
_assertPresentInParentList():void {
var p = this._parent;
if (isBlank(p)) {
return;
@ -108,7 +108,7 @@ export class TreeNode {
/**
* Adds a child to the parent node. The child MUST NOT be a part of a tree.
*/
addChild(child:TreeNode) {
addChild(child:TreeNode):void {
if (isPresent(this._tail)) {
this._tail._next = child;
this._tail = child;
@ -124,7 +124,7 @@ export class TreeNode {
* Adds a child to the parent node after a given sibling.
* The child MUST NOT be a part of a tree and the sibling must be present.
*/
addChildAfter(child:TreeNode, prevSibling:TreeNode) {
addChildAfter(child:TreeNode, prevSibling:TreeNode):void {
this._assertConsistency();
if (isBlank(prevSibling)) {
var prevHead = this._head;
@ -146,7 +146,7 @@ export class TreeNode {
/**
* Detaches a node from the parent's tree.
*/
remove() {
remove():void {
this._assertConsistency();
if (isBlank(this.parent)) return;
var nextSibling = this._next;
@ -209,7 +209,7 @@ export class DirectiveDependency extends Dependency {
this._verify();
}
_verify() {
_verify():void {
var count = 0;
if (isPresent(this.propSetterName)) count++;
if (isPresent(this.queryDirective)) count++;

View File

@ -28,7 +28,7 @@ export class NgElement {
return domViewRef.delegate.boundElements[this._boundElementIndex];
}
getAttribute(name:string) {
getAttribute(name:string):string {
return normalizeBlank(DOM.getAttribute(this.domElement, name));
}
}

View File

@ -75,7 +75,7 @@ export class AppView {
this.componentChildViews = componentChildViews;
}
getOrCreateViewContainer(boundElementIndex:number) {
getOrCreateViewContainer(boundElementIndex:number):ViewContainer {
var viewContainer = this.viewContainers[boundElementIndex];
if (isBlank(viewContainer)) {
viewContainer = new ViewContainer(this, this.proto.elementBinders[boundElementIndex].nestedProtoView, this.elementInjectors[boundElementIndex]);
@ -84,7 +84,7 @@ export class AppView {
return viewContainer;
}
setLocal(contextName: string, value) {
setLocal(contextName: string, value):void {
if (!this.hydrated()) throw new BaseException('Cannot set locals on dehydrated view.');
if (!MapWrapper.contains(this.proto.variableBindings, contextName)) {
return;
@ -93,7 +93,7 @@ export class AppView {
this.locals.set(templateName, value);
}
hydrated() {
hydrated():boolean {
return isPresent(this.context);
}
@ -106,14 +106,14 @@ export class AppView {
* @param {*} eventObj
* @param {int} binderIndex
*/
triggerEventHandlers(eventName: string, eventObj, binderIndex: int) {
triggerEventHandlers(eventName: string, eventObj, binderIndex: int): void {
var locals = MapWrapper.create();
MapWrapper.set(locals, '$event', eventObj);
this.dispatchEvent(binderIndex, eventName, locals);
}
// dispatch to element injector or text nodes based on context
notifyOnBinding(b:BindingRecord, currentValue:any) {
notifyOnBinding(b:BindingRecord, currentValue:any): void {
if (b.isElement()) {
this.renderer.setElementProperty(
this.render, b.elementIndex, b.propertyName, currentValue
@ -199,7 +199,7 @@ export class AppProtoView {
//TODO: Tobias or Victor. Moving it into the constructor.
// this work should be done the constructor of AppProtoView once we separate
// AppProtoView and ProtoViewBuilder
getVariableBindings() {
getVariableBindings(): List {
if (isPresent(this._variableBindings)) {
return this._variableBindings;
}
@ -217,7 +217,7 @@ export class AppProtoView {
//TODO: Tobias or Victor. Moving it into the constructor.
// this work should be done the constructor of ProtoView once we separate
// AppProtoView and ProtoViewBuilder
getdirectiveRecords() {
getdirectiveRecords(): List {
if (isPresent(this._directiveRecords)) {
return this._directiveRecords;
}
@ -236,7 +236,7 @@ export class AppProtoView {
return this._directiveRecords;
}
bindVariable(contextName:string, templateName:string) {
bindVariable(contextName:string, templateName:string): void {
MapWrapper.set(this.variableBindings, contextName, templateName);
MapWrapper.set(this.protoLocals, templateName, null);
}
@ -252,7 +252,7 @@ export class AppProtoView {
/**
* Adds a text node binding for the last created ElementBinder via bindElement
*/
bindTextNode(expression:AST) {
bindTextNode(expression:AST):void {
var textNodeIndex = this.textNodesWithBindingCount++;
var b = BindingRecord.createForTextNode(expression, textNodeIndex);
ListWrapper.push(this.bindings, b);
@ -261,7 +261,7 @@ export class AppProtoView {
/**
* Adds an element property binding for the last created ElementBinder via bindElement
*/
bindElementProperty(expression:AST, setterName:string) {
bindElementProperty(expression:AST, setterName:string):void {
var elementIndex = this.elementBinders.length-1;
var b = BindingRecord.createForElement(expression, elementIndex, setterName);
ListWrapper.push(this.bindings, b);
@ -280,7 +280,7 @@ export class AppProtoView {
* @param {int} directiveIndex The directive index in the binder or -1 when the event is not bound
* to a directive
*/
bindEvent(eventBindings: List<renderApi.EventBinding>, directiveIndex: int = -1) {
bindEvent(eventBindings: List<renderApi.EventBinding>, directiveIndex: int = -1): void {
var elBinder = this.elementBinders[this.elementBinders.length - 1];
var events = elBinder.hostListeners;
if (isBlank(events)) {
@ -306,7 +306,7 @@ export class AppProtoView {
directiveIndex:number,
expression:AST,
setterName:string,
setter:SetterFn) {
setter:SetterFn): void {
var elementIndex = this.elementBinders.length-1;
var directiveRecord = this._getDirectiveRecord(elementIndex, directiveIndex);
@ -314,7 +314,7 @@ export class AppProtoView {
ListWrapper.push(this.bindings, b);
}
_getDirectiveRecord(elementInjectorIndex:number, directiveIndex:number) {
_getDirectiveRecord(elementInjectorIndex:number, directiveIndex:number): DirectiveRecord {
var id = elementInjectorIndex * 100 + directiveIndex;
var protoElementInjector = this.elementBinders[elementInjectorIndex].protoElementInjector;

View File

@ -27,17 +27,17 @@ export class ViewContainer {
this._views = [];
}
getRender() {
getRender():ViewContainerRef {
return new ViewContainerRef(this.parentView.render, this.elementInjector.getBoundElementIndex());
}
internalClearWithoutRender() {
internalClearWithoutRender():void {
for (var i = this._views.length - 1; i >= 0; i--) {
this._detachInjectors(i);
}
}
clear() {
clear():void {
for (var i = this._views.length - 1; i >= 0; i--) {
this.remove(i);
}
@ -47,22 +47,22 @@ export class ViewContainer {
return this._views[index];
}
get length() {
get length() /* :int */ {
return this._views.length;
}
_siblingInjectorToLinkAfter(index: number) {
_siblingInjectorToLinkAfter(index: number):eiModule.ElementInjector {
if (index == 0) return null;
return ListWrapper.last(this._views[index - 1].rootElementInjectors)
}
hydrated() {
hydrated():boolean {
return this.parentView.hydrated();
}
// TODO(rado): profile and decide whether bounds checks should be added
// to the methods below.
create(atIndex=-1, protoView:viewModule.AppProtoView = null, injector:Injector = null): viewModule.AppView {
create(atIndex:number=-1, protoView:viewModule.AppProtoView = null, injector:Injector = null): viewModule.AppView {
if (atIndex == -1) atIndex = this._views.length;
if (!this.hydrated()) throw new BaseException(
'Cannot create views on a dehydrated ViewContainer');
@ -77,7 +77,7 @@ export class ViewContainer {
return newView;
}
insert(view, atIndex=-1): viewModule.AppView {
insert(view:viewModule.AppView, atIndex:number=-1): viewModule.AppView {
if (atIndex == -1) atIndex = this._views.length;
this._insertInjectors(view, atIndex);
this.parentView.changeDetector.addChild(view.changeDetector);
@ -85,7 +85,7 @@ export class ViewContainer {
return view;
}
_insertInjectors(view, atIndex): viewModule.AppView {
_insertInjectors(view:viewModule.AppView, atIndex:number): viewModule.AppView {
ListWrapper.insert(this._views, atIndex, view);
this._linkElementInjectors(this._siblingInjectorToLinkAfter(atIndex), view);
@ -96,7 +96,7 @@ export class ViewContainer {
return ListWrapper.indexOf(this._views, view);
}
remove(atIndex=-1) {
remove(atIndex:number=-1):void {
if (atIndex == -1) atIndex = this._views.length - 1;
var view = this._views[atIndex];
// opposite order as in create
@ -110,7 +110,7 @@ export class ViewContainer {
* The method can be used together with insert to implement a view move, i.e.
* moving the dom nodes while the directives in the view stay intact.
*/
detach(atIndex=-1): viewModule.AppView {
detach(atIndex:number=-1): viewModule.AppView {
if (atIndex == -1) atIndex = this._views.length - 1;
var detachedView = this._detachInjectors(atIndex);
detachedView.changeDetector.remove();
@ -118,20 +118,20 @@ export class ViewContainer {
return detachedView;
}
_detachInjectors(atIndex): viewModule.AppView {
_detachInjectors(atIndex:number): viewModule.AppView {
var detachedView = this.get(atIndex);
ListWrapper.removeAt(this._views, atIndex);
this._unlinkElementInjectors(detachedView);
return detachedView;
}
_linkElementInjectors(sibling, view) {
_linkElementInjectors(sibling, view:viewModule.AppView):void {
for (var i = view.rootElementInjectors.length - 1; i >= 0; i--) {
view.rootElementInjectors[i].linkAfter(this.elementInjector, sibling);
}
}
_unlinkElementInjectors(view) {
_unlinkElementInjectors(view:viewModule.AppView):void {
for (var i = 0; i < view.rootElementInjectors.length; ++i) {
view.rootElementInjectors[i].unlink();
}