Bi-directional binding for Mithril. Works as a component and as a custom attribute.
npm install m.attrs.bidiAs a custom attribute (requires custom attribute fork):
``javascript`
m( 'input', {
bidi : valueProp
} )
...Or as a component (ensures lexical reference):
`javascript`
bidi( {}, m( 'input' ), valueProp )
`shellNPM
npm install m.attrs.bidi --save
The plugin will attach itself as m.attrs.bidi and return / export / expose the same object as a module. The entity in question is both a component and a transformation function that works as a custom attribute.
`javascript
// Node / Browserify
var bidi = require( 'm.attrs.bidi' )// ES6
import bidi from 'm.attrs.bidi'
// RequireJS
require( [ 'm.attrs.bidi' ], function( bidi ){
/ ... /
} )
// HTML
`$3
#### Dropdowns
Dropdowns will need their options passed in as normal.
`javascript
m( 'select', {
bidi : valueProp
},
list.map( function( item ){
return m( 'option', item )
} )
)
`#### Radio buttons
In the same way, radio buttons need to have values specified
`javascript
m( 'input[type=radio]', {
bidi : valueProp,
value : item1
} ),
m( 'input[type=radio]', {
bidi : valueProp,
value : item2
} )
`#### Checkboxes
`javascript
m( 'input[type=checkbox]', {
bidi : valueProp
} )
``Custom attributes are a feature request for Mithril. You may be interested in the Github discussion, and in the fork of Mithril that implements the proposal.