Skip to content
Felipe Manga edited this page Jul 21, 2019 · 1 revision

Summary

FemtoIDE's functionality can be extended by means of plugins written in javascript. By default, these are located in the plugins folder, though you can change it or add your own folder in config.js.

Anatomy of a Plugin

Plugins generally follow this structure:

APP.addPlugin("name-of-your-plugin", ["names-of-dependencies"], [dependencies] => {
});

The anonymous function is called only once all the dependencies have loaded. Here is an example of two plugins, A and B, where B needs A:

APP.addPlugin("A", [], _ => {
  class PluginA {
  }
  return PluginA;
});

APP.addPlugin("B", ["A"], [A] => {
  class PluginB extends A {
  }
});

For a plugin to actually be able to do something useful, it needs to be able to receive and emit events to the rest of the application. To receive events, add your plugin instance to the APP event bus:

APP.addPlugin("A", [], _ => {
  class PluginA {
    onOpenProject(){ // listen for the "onOpenProject" event
    }
  }

  APP.add(new PluginA()); // create a PluginA and register it in the event bus

  return PluginA;
});

To emit events, simply call them as functions in the event bus:

APP.log("Hello world"); // emit a log event that will be sent to all objects with a log event listener. 

An event can have various listeners. To see which events are currently being listened to, use APP.documentation() (or simply documentation() in the console).

Clone this wiki locally