mirror of
https://github.com/flarum/core.git
synced 2025-07-12 20:36:28 +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:
41
js/src/common/extend/Model.js
Normal file
41
js/src/common/extend/Model.js
Normal file
@ -0,0 +1,41 @@
|
||||
export default class Routes {
|
||||
type;
|
||||
attributes = [];
|
||||
hasOnes = [];
|
||||
hasManys = [];
|
||||
|
||||
constructor(type, model = null) {
|
||||
this.type = type;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
attribute(name) {
|
||||
this.attributes.push(name);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
hasOne(type) {
|
||||
this.hasOnes.push(type);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
hasMany(type) {
|
||||
this.hasManys.push(type);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
extend(app, extension) {
|
||||
if (this.model) {
|
||||
app.store.models[this.type] = this.model;
|
||||
}
|
||||
|
||||
const model = app.store.models[this.type];
|
||||
|
||||
this.attributes.forEach(name => model.prototype[name] = model.attribute(name));
|
||||
this.hasOnes.forEach(name => model.prototype[name] = model.hasOne(name));
|
||||
this.hasManys.forEach(name => model.prototype[name] = model.hasMany(name));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user