add config context
This commit is contained in:
parent
eb353aa808
commit
ff2cb55a04
4 changed files with 74 additions and 5 deletions
|
|
@ -45,3 +45,17 @@ test('issue99 regression', function() {
|
|||
m.render(dummyEl, view2);
|
||||
equal(dummyEl.innerHTML, '<div><span>0</span></div>', '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);
|
||||
})
|
||||
|
|
@ -454,6 +454,31 @@ function testMithril(mock) {
|
|||
var children = root.childNodes[0].childNodes
|
||||
return children.length == 3 && children[0].nodeValue == "d" && children[1].nodeValue == "e"
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
|
||||
var success = false
|
||||
m.render(root, m("div", {config: function(elem, isInitialized, ctx) {ctx.data = 1}}))
|
||||
m.render(root, m("div", {config: function(elem, isInitialized, ctx) {success = ctx.data === 1}}))
|
||||
return success
|
||||
})
|
||||
test(function() {
|
||||
var root = mock.document.createElement("div")
|
||||
|
||||
var index = 0;
|
||||
var success = true;
|
||||
var statefulConfig = function(elem, isInitialized, ctx) {ctx.data = index++}
|
||||
var node = m("div", {config: statefulConfig});
|
||||
m.render(root, [node, node]);
|
||||
|
||||
index = 0;
|
||||
var checkConfig = function(elem, isInitialized, ctx) {
|
||||
success = success && (ctx.data === index++)
|
||||
}
|
||||
node = m("div", {config: checkConfig});
|
||||
m.render(root, [node, node]);
|
||||
return success;
|
||||
})
|
||||
//end m.render
|
||||
|
||||
//m.redraw
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue