Allow m.prop to be JSON.stringify-ed

This commit is contained in:
Thomas Dy 2014-04-19 10:39:01 +08:00
parent d7b64ceab2
commit 95affb1cb2
2 changed files with 13 additions and 1 deletions

View file

@ -313,10 +313,14 @@ new function(window) {
//model
m.prop = function(store) {
return function() {
var f = function() {
if (arguments.length) store = arguments[0]
return store
}
f.toJSON = function() {
return store
}
return f
}
m.deferred = function() {

View file

@ -389,6 +389,14 @@ function testMithril(mock) {
prop("foo")
return prop() == "foo"
})
test(function() {
var prop = m.prop("test")
return JSON.stringify(prop) == "\"test\""
})
test(function() {
var obj = { prop: m.prop("test") }
return JSON.stringify(obj) == "{\"prop\":\"test\"}"
})
//m.request
test(function() {