allow m.redraw(true) to force-render component
This commit is contained in:
parent
cd403225a2
commit
2d5d042131
2 changed files with 30 additions and 3 deletions
|
|
@ -245,7 +245,7 @@ var m = (function app(window, undefined) {
|
||||||
var controllerIndex = m.redraw.strategy() == "diff" && cached.views ? cached.views.indexOf(view) : -1
|
var controllerIndex = m.redraw.strategy() == "diff" && cached.views ? cached.views.indexOf(view) : -1
|
||||||
var controller = controllerIndex > -1 ? cached.controllers[controllerIndex] : new (data.controller || noop)
|
var controller = controllerIndex > -1 ? cached.controllers[controllerIndex] : new (data.controller || noop)
|
||||||
var key = data && data.attrs && data.attrs.key
|
var key = data && data.attrs && data.attrs.key
|
||||||
data = pendingRequests == 0 || (cached && cached.controllers && cached.controllers.indexOf(controller) > -1) ? data.view(controller) : {tag: "placeholder"}
|
data = (pendingRequests == 0 || forcing) || (cached && cached.controllers && cached.controllers.indexOf(controller) > -1) ? data.view(controller) : {tag: "placeholder"}
|
||||||
if (data.subtree === "retain") return cached;
|
if (data.subtree === "retain") return cached;
|
||||||
if (key) {
|
if (key) {
|
||||||
if (!data.attrs) data.attrs = {}
|
if (!data.attrs) data.attrs = {}
|
||||||
|
|
@ -606,10 +606,11 @@ var m = (function app(window, undefined) {
|
||||||
return controllers[index]
|
return controllers[index]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var redrawing = false
|
var redrawing = false, forcing = false
|
||||||
m.redraw = function(force) {
|
m.redraw = function(force) {
|
||||||
if (redrawing) return
|
if (redrawing) return
|
||||||
redrawing = true
|
redrawing = true
|
||||||
|
if (force) forcing = true
|
||||||
//lastRedrawId is a positive number if a second redraw is requested before the next animation frame
|
//lastRedrawId is a positive number if a second redraw is requested before the next animation frame
|
||||||
//lastRedrawID is null if it's the first redraw and not an event handler
|
//lastRedrawID is null if it's the first redraw and not an event handler
|
||||||
if (lastRedrawId && force !== true) {
|
if (lastRedrawId && force !== true) {
|
||||||
|
|
@ -624,7 +625,7 @@ var m = (function app(window, undefined) {
|
||||||
redraw();
|
redraw();
|
||||||
lastRedrawId = $requestAnimationFrame(function() {lastRedrawId = null}, FRAME_BUDGET)
|
lastRedrawId = $requestAnimationFrame(function() {lastRedrawId = null}, FRAME_BUDGET)
|
||||||
}
|
}
|
||||||
redrawing = false
|
redrawing = forcing = false
|
||||||
};
|
};
|
||||||
m.redraw.strategy = m.prop();
|
m.redraw.strategy = m.prop();
|
||||||
function redraw() {
|
function redraw() {
|
||||||
|
|
|
||||||
|
|
@ -1339,6 +1339,32 @@ function testMithril(mock) {
|
||||||
|
|
||||||
return initialized === false
|
return initialized === false
|
||||||
})
|
})
|
||||||
|
test(function() {
|
||||||
|
var root = mock.document.createElement("div")
|
||||||
|
var el
|
||||||
|
var FooPage = {
|
||||||
|
view: function(ctrl) {
|
||||||
|
return m('div', [
|
||||||
|
m('button', {onclick: function() {
|
||||||
|
ctrl.bar = true;
|
||||||
|
m.redraw(true);
|
||||||
|
el = root.childNodes[0].childNodes[1]
|
||||||
|
}}, 'click me'),
|
||||||
|
ctrl.bar ? m.component(BarComponent) : ''
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var BarComponent = {
|
||||||
|
view: function() {
|
||||||
|
return m('#bar', 'test');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
m.mount(root, FooPage);
|
||||||
|
|
||||||
|
root.childNodes[0].childNodes[0].onclick({})
|
||||||
|
|
||||||
|
return el.id == "bar"
|
||||||
|
})
|
||||||
|
|
||||||
//m.withAttr
|
//m.withAttr
|
||||||
test(function() {
|
test(function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue