Utility for Mithril creating attributes
First create the builder, use it and get the attributes to use them in the mithril function.
var m = require('mithril')
var ma = require('mithril-util-attributes')
var div = m( "div", ma().id( "0" ).get() )
var div = m( "div", ma().css( "highlight", ctrl.isHighlighted(), "bold", ctrl.isBold(), "italic", ctrl.isItalic() ).get() )
// when ctrl.isHighlighted() == true
// when ctrl.isBold() == false
// when ctrl.isItalic() == true
// will create { 'class': 'highlight italic' }
m( "input", ma().name( "description" ).value( "initialValue" ).oninput( ctrl.setDescription ).get() )
Creates a new instance of the builder. If you have attributes already, you can them handover via optional parameter.
Creates a new instance of the builder. If you have attributes already, you can them handover via optional parameter.
Creates the attribute object.
Can be invoked as often you like. The last class of two or more identical class strings will win.
Builder builder.oninput( Function callback [, Boolean useMithrilWithAttrFunction [, Object thisArg ]] )
Builder builder.onchange( Function callback [, Boolean useMithrilWithAttrFunction [, Object thisArg ]] )
Builder builder.withAttr( String attrName, String event, Object initialValue, Function callback [, Object thisArg ] )
This will invoke internally:
attrs[attrName] = initialValue
attrs[event] = m.withAttr( attrName, callback, thisArg )
Set any attribute you like.