mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 04:33:47 +08:00
f591851cb2
Instead of: <a href={app.route.user(user)} config={m.route}> We can use: <a route={app.route.user(user)}>
41 lines
813 B
JavaScript
41 lines
813 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);
|
|
}
|
|
|
|
if (node.attrs.route) {
|
|
node.attrs.href = node.attrs.route;
|
|
node.attrs.config = m.route;
|
|
|
|
delete node.attrs.route;
|
|
}
|
|
|
|
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;
|
|
}
|