2015-08-26 16:22:29 +09:30
|
|
|
import Component from '../Component';
|
|
|
|
|
|
|
|
export default function patchMithril(global) {
|
|
|
|
const mo = global.m;
|
|
|
|
|
2020-04-17 11:57:55 +02:00
|
|
|
const m = function (comp, ...args) {
|
2015-08-26 16:22:29 +09:30
|
|
|
if (comp.prototype && comp.prototype instanceof Component) {
|
2017-11-05 16:12:26 +10:30
|
|
|
let children = args.slice(1);
|
|
|
|
if (children.length === 1 && Array.isArray(children[0])) {
|
2020-04-17 11:57:55 +02:00
|
|
|
children = children[0];
|
2017-11-05 16:12:26 +10:30
|
|
|
}
|
|
|
|
|
|
|
|
return comp.component(args[0], children);
|
2015-08-26 16:22:29 +09:30
|
|
|
}
|
|
|
|
|
2015-09-18 13:06:37 +09:30
|
|
|
const node = mo.apply(this, arguments);
|
|
|
|
|
|
|
|
if (node.attrs.bidi) {
|
|
|
|
m.bidi(node, node.attrs.bidi);
|
|
|
|
}
|
|
|
|
|
2015-09-22 17:09:38 +09:30
|
|
|
if (node.attrs.route) {
|
|
|
|
node.attrs.href = node.attrs.route;
|
|
|
|
node.attrs.config = m.route;
|
|
|
|
|
|
|
|
delete node.attrs.route;
|
|
|
|
}
|
|
|
|
|
2015-09-18 13:06:37 +09:30
|
|
|
return node;
|
|
|
|
};
|
2015-08-26 16:22:29 +09:30
|
|
|
|
2020-04-17 11:57:55 +02:00
|
|
|
Object.keys(mo).forEach((key) => (m[key] = mo[key]));
|
2015-08-26 16:22:29 +09:30
|
|
|
|
2015-08-31 12:04:51 +09:30
|
|
|
/**
|
|
|
|
* Redraw only if not in the middle of a computation (e.g. a route change).
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2020-04-17 11:57:55 +02:00
|
|
|
m.lazyRedraw = function () {
|
2015-08-31 12:04:51 +09:30
|
|
|
m.startComputation();
|
|
|
|
m.endComputation();
|
|
|
|
};
|
|
|
|
|
2015-08-26 16:22:29 +09:30
|
|
|
global.m = m;
|
|
|
|
}
|