Last active
January 26, 2018 10:44
-
-
Save volnei/9a023abc77bc6c30931b8f86bc6f1c07 to your computer and use it in GitHub Desktop.
A mithril bind function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use this function to bind input/select/textarea value (or other properties) to model. | |
* eg. m('input', {oninput: m.bind(myModel, 'property')}) | |
* or | |
* eg. m('input[type=checkbox]', {onchange: m.bind('checked', myModel, 'property')} | |
* | |
* enjoy! | |
*/ | |
m.bind = function(attr, obj, prop) { | |
if (arguments.length == 2) { | |
prop = obj | |
obj = attr | |
attr = 'value' | |
} | |
return m.withAttr(attr, function(value) {obj[prop] = value}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment