mithril.js

Mithril.js: Should two child components talk to each other through their parent's controller?

拟墨画扇 提交于 2019-12-08 03:47:12
问题 I'm a bit stuck looking for the right way to do the following. I have a parent component with two child components (see simplified code below). I would like to know the proper way for ChildA , when its button is pressed, to 'invoke' ChildB . They should communicate through the parent, but should they communicate through their controllers? In that case the parent has to pass its controller to the controllers of the children. Parent = { view: function () { m.component(ChildA); m.component

How to detect model parameter change event in mithril.js?

非 Y 不嫁゛ 提交于 2019-12-02 01:39:16
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.name) } testModel = new TestModel({name: "John"}) code above declare a model and it works perfectly as getter/setter. but how can I set an event listener for the model event like Backbone's listenTo('model',"change",callbackFunc) ? all sample codes I saw are setting events for actual user actions like click , keyup or onchange .but never listen to actual model value's state directly. am I missing something or am I

How to convert a string into a HTML element in Mithril?

夙愿已清 提交于 2019-12-01 18:38:54
Suppose I have a string <span class="msg">Text goes here</span> .I need to use this string as a HTML element in my webpage. Any ideas on how to do it? Barney Mithril provides the m.trust method for this. At the place in your view where you want the HTML output, write m.trust( '<span class="msg">Text goes here</span>' ) and you should be sorted. Mithril it's powerfull thanks to the virtual dom, in the view you if you want to create a html element you use: m("htmlattribute.classeCss" , "value"); So in your case: m("span.msg" , "Text goes here"); Try creating a container you wish to hold your