Skip to content

Instantly share code, notes, and snippets.

@avesus
Last active August 29, 2015 14:27
Show Gist options
  • Save avesus/b0bd1538080090e34521 to your computer and use it in GitHub Desktop.
Save avesus/b0bd1538080090e34521 to your computer and use it in GitHub Desktop.
Patches Mithril to accept components as well as strings
// If you need a license, this is under the ISC license.
// In golfed ES6, just because I could... (84 characters)
this.m=(o=>Object.assign((...a)=>(typeof a[0]=='string'?o:o.component)(...a),o))(m);
// If you need a license, this is under the ISC license.
// In ES6, just because I could...
this.m = ((old, m) => {
m = (name, ...rest) => (typeof name === 'string' ? old : old.component)(name, ...rest);
Object.assign(m, old);
return m;
})(m);
// If you need a license, this is under the ISC license.
this.m = (function (old) {
function m(name) {
return (typeof name === 'string' ? old : old.component)
.apply(this, arguments);
}
for (var p in old) if ({}.hasOwnProperty.call(p)) {
m[p] = old[p];
}
return m;
})(m);
// If you need a license, this is under the ISC license.
this.m=function(o){function m(n){return(typeof n==='string'?o:o.component).apply(this,arguments)}for(var p in o)if({}.hasOwnProperty.call(p))m[p]=o[p];return m}(m);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment