mirror of
https://github.com/flarum/core.git
synced 2025-07-13 04:46:24 +02:00
[WIP] JS Extender API foundation (#1468)
* Run extenders exported by extensions * Add some basic extenders * Patch Mithril as the very first thing so extension code can run safely * Load the payload into the app before booting extensions * Setup default routes before booting extensions
This commit is contained in:
@ -10,7 +10,6 @@ import Session from './Session';
|
||||
import extract from './utils/extract';
|
||||
import Drawer from './utils/Drawer';
|
||||
import mapRoutes from './utils/mapRoutes';
|
||||
import patchMithril from './utils/patchMithril';
|
||||
import RequestError from './utils/RequestError';
|
||||
import ScrollListener from './utils/ScrollListener';
|
||||
import { extend } from './extend';
|
||||
@ -21,6 +20,7 @@ import Discussion from './models/Discussion';
|
||||
import Post from './models/Post';
|
||||
import Group from './models/Group';
|
||||
import Notification from './models/Notification';
|
||||
import { flattenDeep } from 'lodash-es';
|
||||
|
||||
/**
|
||||
* The `App` class provides a container for an application, as well as various
|
||||
@ -115,16 +115,17 @@ export default class Application {
|
||||
*/
|
||||
requestError = null;
|
||||
|
||||
data;
|
||||
|
||||
title = '';
|
||||
titleCount = 0;
|
||||
|
||||
boot(data) {
|
||||
this.data = data;
|
||||
|
||||
this.translator.locale = data.locale;
|
||||
|
||||
patchMithril(window);
|
||||
load(payload) {
|
||||
this.data = payload;
|
||||
this.translator.locale = payload.locale;
|
||||
}
|
||||
|
||||
boot() {
|
||||
this.initializers.toArray().forEach(initializer => initializer(this));
|
||||
|
||||
this.store.pushPayload({data: this.data.resources});
|
||||
@ -139,6 +140,18 @@ export default class Application {
|
||||
this.mount();
|
||||
}
|
||||
|
||||
bootExtensions(extensions) {
|
||||
Object.keys(extensions).forEach(name => {
|
||||
const extension = extensions[name];
|
||||
|
||||
const extenders = flattenDeep(extension.extend);
|
||||
|
||||
for (const extender of extenders) {
|
||||
extender.extend(this, { name, exports: extension });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mount() {
|
||||
this.modal = m.mount(document.getElementById('modal'), <ModalManager/>);
|
||||
this.alerts = m.mount(document.getElementById('alerts'), <AlertManager/>);
|
||||
|
Reference in New Issue
Block a user