Skip to content Skip to sidebar Skip to footer

How To Detect Model Parameter Change Event In Mithril.js?

I recently started learning mithril.js and I'm wondering how can I make very basic Model -> View one way data binding app. TestModel = function(data){ this.name = m.prop(data.

Solution 1:

One of the key ideas with Mithril is that changes usually happens after an event:

  • A user action like onclick or keyup defined in a m() view template
  • An ajax request made with m.request

Mithril automatically redraws after those, alleviating the need for most listeners.

If you are updating your models through some other method and you need to redraw manually, use m.redraw or m.startComputation / m.endComputation. Thanks to Mithril's DOM diff algorithm, redraws are very cheap so don't be afraid to use them (with some common sense, of course!) Check out the m.redraw documentation for more info.


Post a Comment for "How To Detect Model Parameter Change Event In Mithril.js?"