mirror of
https://github.com/flarum/core.git
synced 2025-07-20 08:11:27 +02:00
Webpack (#1367)
* Replace gulp with webpack and npm scripts for JS compilation * Set up Travis CI to commit compiled JS * Restructure `js` directory; only one instance of npm, forum/admin are "submodules" * Refactor JS initializers into Application subclasses * Maintain partial compatibility API (importing from absolute paths) for extensions * Remove minification responsibility from PHP asset compiler * Restructure `less` directory
This commit is contained in:
45
js/src/common/utils/patchMithril.js
Normal file
45
js/src/common/utils/patchMithril.js
Normal file
@@ -0,0 +1,45 @@
|
||||
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) {
|
||||
let children = args.slice(1);
|
||||
if (children.length === 1 && Array.isArray(children[0])) {
|
||||
children = children[0]
|
||||
}
|
||||
|
||||
return comp.component(args[0], children);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user