From 95affb1cb2084a872465f96edd74280d4aa230d4 Mon Sep 17 00:00:00 2001 From: Thomas Dy Date: Sat, 19 Apr 2014 10:39:01 +0800 Subject: [PATCH] Allow m.prop to be JSON.stringify-ed --- mithril.js | 6 +++++- tests/mithril-tests.js | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index ed6d9b52..7db73997 100644 --- a/mithril.js +++ b/mithril.js @@ -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() { diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index ad2aefe8..55923354 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -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() {