refactor(ts'ify): ts’ify mocks, directives and test_lib

Also cleans up global types.
This commit is contained in:
Tobias Bosch
2015-05-20 17:19:46 -07:00
parent c5996529c3
commit aec51d616b
51 changed files with 610 additions and 671 deletions

View File

@ -1,21 +1,15 @@
import {Directive} from 'angular2/src/core/annotations_impl/annotations';
import {Directive} from 'angular2/annotations';
import {ElementRef} from 'angular2/core';
import {isPresent} from 'angular2/src/facade/lang';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
@Directive({
selector: '[class]',
properties: {
'iterableChanges': 'class | keyValDiff'
}
})
@Directive({selector: '[class]', properties: {'iterableChanges': 'class | keyValDiff'}})
export class CSSClass {
_domEl;
constructor(ngEl: ElementRef) {
this._domEl = ngEl.domElement;
}
constructor(ngEl: ElementRef) { this._domEl = ngEl.domElement; }
_toggleClass(className, enabled):void {
_toggleClass(className, enabled): void {
if (enabled) {
DOM.addClass(this._domEl, className);
} else {
@ -26,7 +20,8 @@ export class CSSClass {
set iterableChanges(changes) {
if (isPresent(changes)) {
changes.forEachAddedItem((record) => { this._toggleClass(record.key, record.currentValue); });
changes.forEachChangedItem((record) => { this._toggleClass(record.key, record.currentValue); });
changes.forEachChangedItem(
(record) => { this._toggleClass(record.key, record.currentValue); });
changes.forEachRemovedItem((record) => {
if (record.previousValue) {
DOM.removeClass(this._domEl, record.key);

View File

@ -1,6 +1,5 @@
import {Directive} from 'angular2/src/core/annotations_impl/annotations';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
import {ViewRef, ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
import {Directive} from 'angular2/annotations';
import {ViewContainerRef, ViewRef, ProtoViewRef} from 'angular2/core';
import {isPresent, isBlank} from 'angular2/src/facade/lang';
import {ListWrapper} from 'angular2/src/facade/collection';
@ -36,16 +35,12 @@ import {ListWrapper} from 'angular2/src/facade/collection';
*
* @exportedAs angular2/directives
*/
@Directive({
selector: '[ng-for][ng-for-of]',
properties: {
'iterableChanges': 'ngForOf | iterableDiff'
}
})
export class NgFor {
@Directive(
{selector: '[ng-for][ng-for-of]', properties: {'iterableChanges': 'ngForOf | iterableDiff'}})
export class NgFor {
viewContainer: ViewContainerRef;
protoViewRef: ProtoViewRef;
constructor(viewContainer:ViewContainerRef, protoViewRef: ProtoViewRef) {
constructor(viewContainer: ViewContainerRef, protoViewRef: ProtoViewRef) {
this.viewContainer = viewContainer;
this.protoViewRef = protoViewRef;
}
@ -59,19 +54,16 @@ export class NgFor {
// TODO(rado): check if change detection can produce a change record that is
// easier to consume than current.
var recordViewTuples = [];
changes.forEachRemovedItem(
(removedRecord) => ListWrapper.push(recordViewTuples, new RecordViewTuple(removedRecord, null))
);
changes.forEachRemovedItem((removedRecord) => ListWrapper.push(
recordViewTuples, new RecordViewTuple(removedRecord, null)));
changes.forEachMovedItem(
(movedRecord) => ListWrapper.push(recordViewTuples, new RecordViewTuple(movedRecord, null))
);
changes.forEachMovedItem((movedRecord) => ListWrapper.push(
recordViewTuples, new RecordViewTuple(movedRecord, null)));
var insertTuples = NgFor.bulkRemove(recordViewTuples, this.viewContainer);
changes.forEachAddedItem(
(addedRecord) => ListWrapper.push(insertTuples, new RecordViewTuple(addedRecord, null))
);
(addedRecord) => ListWrapper.push(insertTuples, new RecordViewTuple(addedRecord, null)));
NgFor.bulkInsert(insertTuples, this.viewContainer, this.protoViewRef);

View File

@ -1,19 +1,20 @@
import {Directive} from 'angular2/src/core/annotations_impl/annotations';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
import {ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
import {Directive} from 'angular2/annotations';
import {ViewContainerRef, ProtoViewRef} from 'angular2/core';
import {isBlank} from 'angular2/src/facade/lang';
/**
* Removes or recreates a portion of the DOM tree based on an {expression}.
*
* If the expression assigned to `if` evaluates to a false value then the element is removed from the
* If the expression assigned to `if` evaluates to a false value then the element is removed from
* the
* DOM, otherwise a clone of the element is reinserted into the DOM.
*
* # Example:
*
* ```
* <div *ng-if="errorCount > 0" class="error">
* <!-- Error message displayed when the errorCount property on the current context is greater than 0. -->
* <!-- Error message displayed when the errorCount property on the current context is greater
* than 0. -->
* {{errorCount}} errors detected
* </div>
* ```
@ -26,18 +27,13 @@ import {isBlank} from 'angular2/src/facade/lang';
*
* @exportedAs angular2/directives
*/
@Directive({
selector: '[ng-if]',
properties: {
'ngIf': 'ngIf'
}
})
@Directive({selector: '[ng-if]', properties: {'ngIf': 'ngIf'}})
export class NgIf {
viewContainer: ViewContainerRef;
protoViewRef: ProtoViewRef;
prevCondition: boolean;
constructor(viewContainer: ViewContainerRef, protoViewRef:ProtoViewRef) {
constructor(viewContainer: ViewContainerRef, protoViewRef: ProtoViewRef) {
this.viewContainer = viewContainer;
this.prevCondition = null;
this.protoViewRef = protoViewRef;

View File

@ -1,4 +1,4 @@
import {Directive} from 'angular2/src/core/annotations_impl/annotations';
import {Directive} from 'angular2/annotations';
/**
* The `NgNonBindable` directive tells Angular not to compile or bind the contents of the current
@ -15,9 +15,6 @@ import {Directive} from 'angular2/src/core/annotations_impl/annotations';
*
* @exportedAs angular2/directives
*/
@Directive({
selector: '[ng-non-bindable]',
compileChildren: false
})
@Directive({selector: '[ng-non-bindable]', compileChildren: false})
export class NgNonBindable {
}

View File

@ -1,11 +1,9 @@
import {Directive} from 'angular2/src/core/annotations_impl/annotations';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
import {ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
import {Directive, Parent} from 'angular2/annotations';
import {ViewContainerRef, ProtoViewRef} from 'angular2/core';
import {isPresent, isBlank, normalizeBlank} from 'angular2/src/facade/lang';
import {ListWrapper, List, MapWrapper, Map} from 'angular2/src/facade/collection';
import {Parent} from 'angular2/src/core/annotations_impl/visibility';
class SwitchView {
export class SwitchView {
_viewContainerRef: ViewContainerRef;
_protoViewRef: ProtoViewRef;
@ -14,13 +12,9 @@ class SwitchView {
this._viewContainerRef = viewContainerRef;
}
create() {
this._viewContainerRef.create(this._protoViewRef);
}
create() { this._viewContainerRef.create(this._protoViewRef); }
destroy() {
this._viewContainerRef.clear();
}
destroy() { this._viewContainerRef.clear(); }
}
/**
@ -50,16 +44,11 @@ class SwitchView {
*
* @exportedAs angular2/directives
*/
@Directive({
selector: '[ng-switch]',
properties: {
'ngSwitch': 'ngSwitch'
}
})
@Directive({selector: '[ng-switch]', properties: {'ngSwitch': 'ngSwitch'}})
export class NgSwitch {
_switchValue: any;
_useDefault: boolean;
_valueViews: Map;
_valueViews: Map<any, List<SwitchView>>;
_activeViews: List<SwitchView>;
constructor() {
@ -84,7 +73,7 @@ export class NgSwitch {
this._switchValue = value;
}
_onWhenValueChanged(oldWhen, newWhen, view: SwitchView):void {
_onWhenValueChanged(oldWhen, newWhen, view: SwitchView): void {
this._deregisterView(oldWhen, view);
this._registerView(newWhen, view);
@ -107,7 +96,7 @@ export class NgSwitch {
}
}
_emptyAllActiveViews():void {
_emptyAllActiveViews(): void {
var activeContainers = this._activeViews;
for (var i = 0; i < activeContainers.length; i++) {
activeContainers[i].destroy();
@ -115,7 +104,7 @@ export class NgSwitch {
this._activeViews = ListWrapper.create();
}
_activateViews(views: List<SwitchView>):void {
_activateViews(views: List<SwitchView>): void {
// TODO(vicb): assert(this._activeViews.length === 0);
if (isPresent(views)) {
for (var i = 0; i < views.length; i++) {
@ -134,7 +123,7 @@ export class NgSwitch {
ListWrapper.push(views, view);
}
_deregisterView(value, view: SwitchView):void {
_deregisterView(value, view: SwitchView): void {
// `_whenDefault` is used a marker for non-registered whens
if (value == _whenDefault) return;
var views = MapWrapper.get(this._valueViews, value);
@ -164,27 +153,21 @@ export class NgSwitch {
*
* @exportedAs angular2/directives
*/
@Directive({
selector: '[ng-switch-when]',
properties: {
'ngSwitchWhen' : 'ngSwitchWhen'
}
})
@Directive({selector: '[ng-switch-when]', properties: {'ngSwitchWhen': 'ngSwitchWhen'}})
export class NgSwitchWhen {
_value: any;
_switch: NgSwitch;
_view: SwitchView;
constructor(viewContainer: ViewContainerRef, protoViewRef: ProtoViewRef, @Parent() sswitch: NgSwitch) {
constructor(viewContainer: ViewContainerRef, protoViewRef: ProtoViewRef,
@Parent() sswitch: NgSwitch) {
// `_whenDefault` is used as a marker for a not yet initialized value
this._value = _whenDefault;
this._switch = sswitch;
this._view = new SwitchView(viewContainer, protoViewRef);
}
onDestroy() {
this._switch
}
onDestroy() { this._switch }
set ngSwitchWhen(value) {
this._switch._onWhenValueChanged(this._value, value, this._view);
@ -206,11 +189,10 @@ export class NgSwitchWhen {
*
* @exportedAs angular2/directives
*/
@Directive({
selector: '[ng-switch-default]'
})
@Directive({selector: '[ng-switch-default]'})
export class NgSwitchDefault {
constructor(viewContainer: ViewContainerRef, protoViewRef: ProtoViewRef, @Parent() sswitch: NgSwitch) {
constructor(viewContainer: ViewContainerRef, protoViewRef: ProtoViewRef,
@Parent() sswitch: NgSwitch) {
sswitch._registerView(_whenDefault, new SwitchView(viewContainer, protoViewRef));
}
}