From 20b102b478ca55a72656ad734cc20b976ec32fc4 Mon Sep 17 00:00:00 2001 From: Sergey Kirillov Date: Sat, 31 May 2014 13:38:55 +0300 Subject: [PATCH] Added context for config handlers --- mithril.js | 2 +- tests/e2e/tests.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index b3b260fd..419ca4fd 100644 --- a/mithril.js +++ b/mithril.js @@ -86,7 +86,7 @@ Mithril = m = new function app(window) { cached.nodes.intact = true if (shouldReattach === true) parentElement.insertBefore(node, parentElement.childNodes[index] || null) } - if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew) + if (type.call(data.attrs["config"]) == "[object Function]") data.attrs["config"](node, !isNew, cached.config_context=cached.config_context || {}) } else { var node diff --git a/tests/e2e/tests.js b/tests/e2e/tests.js index a8c03e3d..c9ecbbf7 100644 --- a/tests/e2e/tests.js +++ b/tests/e2e/tests.js @@ -45,3 +45,20 @@ test('issue99 regression', function() { m.render(dummyEl, view2); equal(dummyEl.innerHTML, '
0
', 'view2 should be rendered correctly'); }); + + +test('config handler context', function() { + expect(3); + var view = m('div', {config: function(evt, isInitialized, context){ + equal(context instanceof Object, true); + context.data = 1; + }}) + m.render(dummyEl, view); + + var view = m('div', {config: function(evt, isInitialized, context){ + equal(context instanceof Object, true); + equal(context.data, 1); + }}) + m.render(dummyEl, view); + +})