refactor(change_detection): made ChangeDetector and ProtoChangeDetector interfaces

List of changes:

- Makes ChangeDetector and ProtoChangeDetector interfaces
- Assigns a unique id to every detector
This commit is contained in:
vsavkin
2015-06-18 14:47:38 -07:00
parent ee8da36d08
commit f80f97253c
20 changed files with 134 additions and 93 deletions

View File

@ -0,0 +1,47 @@
import {
ChangeDetector,
ProtoChangeDetector,
DynamicChangeDetector
} from 'angular2/change_detection';
import {SpyObject, proxy} from './test_lib';
// Remove dummy methods after https://github.com/angular/ts2dart/issues/209 is fixed.
@proxy
export class SpyChangeDetector extends SpyObject implements ChangeDetector {
parent: ChangeDetector;
mode: string;
constructor() { super(DynamicChangeDetector, true); }
addChild(cd: ChangeDetector): void { return this.spy("addChild")(cd); }
addShadowDomChild(cd: ChangeDetector): void { return this.spy("addShadowDomChild")(cd); }
removeChild(cd: ChangeDetector): void { return this.spy("removeChild")(cd); }
removeShadowDomChild(cd: ChangeDetector): void { return this.spy("removeShadowDomChild")(cd); }
remove(): void { return this.spy("remove")(); }
hydrate(context: any, locals: any, directives: any): void {
return this.spy("hydrate")(context, locals, directives);
}
dehydrate(): void { return this.spy("dehydrate")(); }
markPathToRootAsCheckOnce(): void { return this.spy("markPathToRootAsCheckOnce")(); }
detectChanges(): void { return this.spy("detectChanges")(); }
checkNoChanges(): void { return this.spy("checkNoChanges")(); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
// Remove dummy methods after https://github.com/angular/ts2dart/issues/209 is fixed.
@proxy
export class SpyProtoChangeDetector extends SpyObject implements ProtoChangeDetector {
constructor() { super(DynamicChangeDetector, true); }
instantiate(v: any): any { return this.spy("instantiate")(v); }
}

View File

@ -187,7 +187,7 @@ class SpyFunction extends gns.SpyFunction {
class SpyObject extends gns.SpyObject {
final Map<String, SpyFunction> _spyFuncs = {};
SpyObject([arg]) {}
SpyObject([arg, arg2]) {}
SpyFunction spy(String funcName) =>
_spyFuncs.putIfAbsent(funcName, () => new SpyFunction(funcName));

View File

@ -280,7 +280,7 @@ export interface GuinessCompatibleSpy extends jasmine.Spy {
}
export class SpyObject {
constructor(type = null) {
constructor(type = null, forceSpyCreation: boolean = false) {
if (type) {
for (var prop in type.prototype) {
var m = null;
@ -293,7 +293,11 @@ export class SpyObject {
// should not matter.
}
if (typeof m === 'function') {
this.spy(prop);
if (forceSpyCreation) {
this.createSpy(prop);
} else {
this.spy(prop);
}
}
}
}
@ -303,8 +307,14 @@ export class SpyObject {
spy(name) {
if (!this[name]) {
this[name] = this._createGuinnessCompatibleSpy(name);
return this.createSpy(name);
} else {
return this[name];
}
}
createSpy(name) {
this[name] = this._createGuinnessCompatibleSpy(name);
return this[name];
}