mirror of
https://github.com/flarum/framework.git
synced 2025-05-22 06:39: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:
@ -2,6 +2,7 @@ import ItemList from 'flarum/utils/ItemList';
|
|||||||
import Alert from 'flarum/components/Alert';
|
import Alert from 'flarum/components/Alert';
|
||||||
import Translator from 'flarum/Translator';
|
import Translator from 'flarum/Translator';
|
||||||
import extract from 'flarum/utils/extract';
|
import extract from 'flarum/utils/extract';
|
||||||
|
import patchMithril from 'flarum/utils/patchMithril';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `App` class provides a container for an application, as well as various
|
* The `App` class provides a container for an application, as well as various
|
||||||
@ -9,6 +10,8 @@ import extract from 'flarum/utils/extract';
|
|||||||
*/
|
*/
|
||||||
export default class App {
|
export default class App {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
patchMithril(window);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The forum model for this application.
|
* The forum model for this application.
|
||||||
*
|
*
|
||||||
|
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