mirror of
https://github.com/flarum/framework.git
synced 2025-02-24 01:20:55 +08:00

Enables quick bidirectional bindings. So instead of this: <input value={prop()} oninput={m.withAttr('value', prop)}/> ... we can do this: <input bidi={prop}/>
34 lines
669 B
JavaScript
34 lines
669 B
JavaScript
import Component from '../Component';
|
|
|
|
export default function patchMithril(global) {
|
|
const mo = global.m;
|
|
|
|
const m = function(comp, ...args) {
|
|
if (comp.prototype && comp.prototype instanceof Component) {
|
|
return comp.component(...args);
|
|
}
|
|
|
|
const node = mo.apply(this, arguments);
|
|
|
|
if (node.attrs.bidi) {
|
|
m.bidi(node, node.attrs.bidi);
|
|
}
|
|
|
|
return node;
|
|
};
|
|
|
|
Object.keys(mo).forEach(key => m[key] = mo[key]);
|
|
|
|
/**
|
|
* Redraw only if not in the middle of a computation (e.g. a route change).
|
|
*
|
|
* @return {void}
|
|
*/
|
|
m.lazyRedraw = function() {
|
|
m.startComputation();
|
|
m.endComputation();
|
|
};
|
|
|
|
global.m = m;
|
|
}
|