feat(Change Detection): Add support for keyed access

This commit is contained in:
Victor Berchet
2014-12-02 13:14:07 +01:00
parent 7bc282d15e
commit 7cb93fd59e
4 changed files with 38 additions and 6 deletions

View File

@ -153,6 +153,15 @@ export function main() {
expect(executeWatch('m', '1 > 2 ? 1 : 2')).toEqual(['m=2']);
});
describe("keyed access", () => {
it("should support accessing a list item", () => {
expect(executeWatch('array[0]', '["foo", "bar"][0]')).toEqual(['array[0]=foo']);
});
it("should support accessing a map item", () => {
expect(executeWatch('map[foo]', '{"foo": "bar"}["foo"]')).toEqual(['map[foo]=bar']);
});
});
describe("formatters", () => {
it("should support formatters", () => {
var formatters = MapWrapper.createFromPairs([
@ -269,6 +278,10 @@ class LoggingDispatcher extends WatchGroupDispatcher {
onRecordChange(record:Record, context) {
ListWrapper.push(this.loggedValues, record.currentValue);
ListWrapper.push(this.log, context + '=' + record.currentValue.toString());
ListWrapper.push(this.log, context + '=' + this._asString(record.currentValue));
}
_asString(value) {
return (value === null ? 'null' : value.toString());
}
}