Skip to content

Commit 743bea5

Browse files
committed
Merge pull request #107 from Kanaye/observable-to-json
Added toJSON to observable and tests for it.
2 parents c552b7d + d34d60d commit 743bea5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/query/observable.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ define([
312312
return value.toString();
313313
}
314314
return String(value);
315+
},
316+
toJSON: function() {
317+
return this();
315318
}
316319
},
317320

test/spec/query/observables.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,4 +562,21 @@
562562
expect(observable.update).toHaveBeenCalled();
563563
});
564564
});
565+
566+
it('can be JSON.stringified', function () {
567+
568+
var values = [42, 'some string', [1,2,3], {
569+
a:'some string',
570+
b: 42,
571+
c: [1,2,34],
572+
d: {a: 'hello'},
573+
e: blocks.observable('that works ?')
574+
}];
575+
576+
for (var i = 0; i < values.length; i++) {
577+
var value = values[i];
578+
expect(JSON.stringify(value)).toBe(JSON.stringify(blocks.observable(value)));
579+
}
580+
581+
});
565582
})();

0 commit comments

Comments
 (0)