mirror of
https://github.com/flarum/framework.git
synced 2025-05-22 14:49:57 +08:00
Monkey patch mithril so we can use JSX component syntax
<Alert foo="bar"/> instead of Alert.component({foo: 'bar'})
This commit is contained in:
17
js/lib/utils/patchMithril.js
Normal file
17
js/lib/utils/patchMithril.js
Normal file
@ -0,0 +1,17 @@
|
||||
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);
|
||||
}
|
||||
|
||||
return mo.apply(this, arguments);
|
||||
}
|
||||
|
||||
Object.keys(mo).forEach(key => m[key] = mo[key]);
|
||||
|
||||
global.m = m;
|
||||
}
|
Reference in New Issue
Block a user