design: add test change_detection
This commit is contained in:
parent
934f31a4fa
commit
69210e4fde
|
@ -48,15 +48,6 @@ export class ProtoWatchGroup {
|
||||||
return watchGroup;
|
return watchGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the context (the object) on which the change detection expressions will
|
|
||||||
* dereference themselves on. Since the WatchGroup can be reused the context
|
|
||||||
* can be re-set many times during the lifetime of the WatchGroup.
|
|
||||||
*
|
|
||||||
* @param context the new context for change dection for the curren WatchGroup
|
|
||||||
*/
|
|
||||||
setContext(context) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WatchGroup {
|
export class WatchGroup {
|
||||||
|
@ -79,6 +70,15 @@ export class WatchGroup {
|
||||||
/// IMPLEMENT
|
/// IMPLEMENT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the context (the object) on which the change detection expressions will
|
||||||
|
* dereference themselves on. Since the WatchGroup can be reused the context
|
||||||
|
* can be re-set many times during the lifetime of the WatchGroup.
|
||||||
|
*
|
||||||
|
* @param context the new context for change dection for the curren WatchGroup
|
||||||
|
*/
|
||||||
|
setContext(context) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WatchGroupDispatcher {
|
export class WatchGroupDispatcher {
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
import {describe, it, expect} from 'test_lib/test_lib';
|
||||||
|
import {ProtoWatchGroup, WatchGroup, WatchGroupDispatcher} from 'change_detection/watch_group';
|
||||||
|
import {DOM} from 'facade/dom';
|
||||||
|
|
||||||
|
|
||||||
|
export function main() {
|
||||||
|
describe('change_detection', function() {
|
||||||
|
describe('ChangeDetection', function() {
|
||||||
|
it('should do simple watching', function() {
|
||||||
|
return; // remove me after getting the test to pass.
|
||||||
|
var person = new Person('misko', 38);
|
||||||
|
var pwg = new ProtoWatchGroup();
|
||||||
|
pwg.watch('name', 'nameToken');
|
||||||
|
pwg.watch('age', 'ageToken');
|
||||||
|
var dispatcher = new LoggingDispatcher();
|
||||||
|
var wg = pwg.instantiate(dispatcher);
|
||||||
|
wg.setContext(person);
|
||||||
|
var cd = new ChangeDetection(wg);
|
||||||
|
cd.detectChanges();
|
||||||
|
expect(dispatcher.log).toEqual(['ageToken=38']);
|
||||||
|
dispatcher.clear();
|
||||||
|
cd.detectChanges();
|
||||||
|
expect(dispatcher.log).toEqual([]);
|
||||||
|
person.age=1;
|
||||||
|
person.name="Misko";
|
||||||
|
cd.detectChanges();
|
||||||
|
expect(dispatcher.log).toEqual(['nameToken=Misko', 'ageToken=1']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class Person {
|
||||||
|
constructor(name:string, age:number) {
|
||||||
|
this.name = null;
|
||||||
|
this.a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Dispatcher extends WatchGroupDispatcher {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue