Reputation: 1145
When changing prop values mithril doesnt auto redraw the view, on press of a button i update my prop as:
something.vm.test(something.vm.test() + 1);
it updates the prop value but doesn't reflect on view by using m.redraw() it works fine ?
Upvotes: 1
Views: 1062
Reputation: 1394
Note that modifying the values of m.prop getter-setters does not trigger redrawing, These functions are internally called by Mithril when you initialize a component via m.mount or m.route, and when you trigger event handlers that were created within templates with m(). So you can use the m.prop() if you want to change the value of var. Look this example :
controller: function() {
var list = [];
var element = m.prop('');
function addElement() {
list.push(element());
element('');
}
return {
list: list,
value: element,
addElement: addElement
}
m('button',{
onclick: ctrl.addElement
}, 'Add')],
In this case element is a m.prop() and the value change when you click the button
Upvotes: 0
Reputation: 764
Basically, m.prop is a reactive data source. this code may help you.
if you want to work outside of mithril block,
embrace prop with m.startComputation()
and m.endComputation()
like this.
m.startComputation();
something.vm.test(something.vm.test() + 1);
m.endComputation();
it works like charm!
Upvotes: 1
Reputation: 14573
Editing props does not trigger redraw, but button click events should (and you should see the changes to the props).
Is it a mithril button using onclick
attribute? Or non-mithril click event?
If you're not using a mithril event you'll need m.redraw()
Upvotes: 1