From 8cc4a862fe615fa100a932e1d3060e48ba39650a Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Fri, 13 Mar 2015 22:54:46 -0400 Subject: [PATCH] #413 fix ctx.retain bug --- mithril.js | 2 +- tests/mithril-tests.js | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/mithril.js b/mithril.js index 3458fef5..d0633555 100644 --- a/mithril.js +++ b/mithril.js @@ -274,7 +274,7 @@ var m = (function app(window, undefined) { } //schedule configs to be called. They are called after `build` finishes running if (typeof data.attrs["config"] === FUNCTION) { - var context = cached.configContext = cached.configContext || {retain: m.redraw.strategy() == "diff"}; + var context = cached.configContext = cached.configContext || {retain: (m.redraw.strategy() == "diff") || undefined}; // bind var callback = function(data, args) { diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index a0f9d307..911bb3e9 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -98,6 +98,27 @@ function testMithril(mock) { return unloaded === true }) + test(function() { + mock.requestAnimationFrame.$resolve() + + var root = mock.document.createElement("div") + var initCount = 0 + var module = {} + module.view = function() { + return m("div", {config: function(el, init) { + if (!init) initCount++ + }}) + } + m.module(root, module) + + mock.requestAnimationFrame.$resolve() + + m.redraw() + + mock.requestAnimationFrame.$resolve() + + return initCount == 1 + }) m.redraw.strategy(undefined) //teardown for m.module tests //m.withAttr @@ -1803,7 +1824,7 @@ function testMithril(mock) { "/a": a }) - return value === false + return !value }) test(function() { mock.requestAnimationFrame.$resolve() @@ -1824,7 +1845,7 @@ function testMithril(mock) { "/a": a }) - return value === true + return value }) test(function() { mock.requestAnimationFrame.$resolve()