Merge pull request #126 from JsSucks/refactor

Rename require to bridge
This commit is contained in:
Alexei Stukov 2018-02-13 18:47:34 +02:00 committed by GitHub
commit cbc727f951
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View File

@ -94,11 +94,12 @@ export default class PluginApi {
}; };
} }
async require(plugin_id) { async bridge(plugin_id) {
const plugin = await PluginManager.waitForPlugin(plugin_id); const plugin = await PluginManager.waitForPlugin(plugin_id);
return plugin.exports; return plugin.bridge;
} }
get require() { return this.import }
import(m) { import(m) {
const module = PluginManager.findPlugin(m); const module = PluginManager.findPlugin(m);
if (module && module.__require) return module.__require; if (module && module.__require) return module.__require;

View File

@ -5,12 +5,12 @@ module.exports = (Plugin, Api, Vendor) => {
return class extends Plugin { return class extends Plugin {
async onstart() { async onstart() {
const example_plugin = await Api.require('example-plugin'); const example_plugin = await Api.bridge('example-plugin');
console.log('Example plugin exports:', example_plugin.test1()); console.log('Example plugin exports:', example_plugin.test1());
} }
async onstop() { async onstop() {
const example_plugin = await Api.require('example-plugin'); const example_plugin = await Api.bridge('example-plugin');
console.log('Example plugin exports:', example_plugin.test2()); console.log('Example plugin exports:', example_plugin.test2());
} }
} }

View File

@ -24,7 +24,7 @@ module.exports = (Plugin, Api, Vendor) => {
Logger.log(e); Logger.log(e);
} }
getExports() { get bridge() {
return { return {
test1: this.test1.bind(this), test1: this.test1.bind(this),
test2: this.test2.bind(this) test2: this.test2.bind(this)