defer calling of configs until DOM exists

This commit is contained in:
Leo Horie 2014-06-05 21:54:51 -04:00
parent 2d8db79cef
commit e82ac2ef71
3 changed files with 43 additions and 1 deletions

View file

@ -1,3 +1,32 @@
//qunit doesn't support Function.prototype.bind...
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
//tests
var dummyEl = document.getElementById('dummy')
test('Mithril accessible as window.m', function() {

View file

@ -479,6 +479,14 @@ function testMithril(mock) {
m.render(root, [node, node]);
return success;
})
test(function() {
var root = mock.document.createElement("div")
var parent
m.render(root, m("div", m("a", {
config: function(el) {parent = el.parentNode.parentNode}
})));
return parent === root
})
//end m.render
//m.redraw