Skip to content

Plugins

sonsoleslp edited this page Aug 22, 2018 · 8 revisions

Plugins are special components that allow Ediphy to have different types of content. They are separate developments that need to fulfill a series of requirements in order to be included in Ediphy. Check the Plugin API section of the documentation in order to learn how to develop your new plugin.

The following functions allow to import and make use of the plugins in Ediphy.

Ediphy.Plugins

This object contains the neccesary methods to load the plugins and to obtain the definitions and instances of themselves , also a series of properties and internal functions.

  • pluginInstancesList: this object contains plugins instances.
  • plugins: this array contains the names of every plugin that wants to be loaded in the application.
  • loadPluginFile: given the plugin name, this function makes an asynchronous call to load the plugin file in the "editor" mode and in "visor" mode. Because of the plugin format, when loaded they are automatically added to the objects Ediphy.Plugins and Ediphy.Visor.Plugins. This is done inside a Promise, that needs to be ended in the asyncronous called so can be resolved and executed the deried code (in this case, plugins instance). So far these plugin properties were private. The following are accessible:
  • get: given the name to a plugin, returns its instance.
  • getAll : return instances of all plugins.
  • getPluginsInView: given the identifier of a view and a boolean parameter, this method makes an API called to obtain the plugins added to the given view. If boolean is positive, the only will return the ones that specified an alias. It works in an asyncronous way.
  • getPluginsInCurrentView: this function makes a call to the method getPluginsInView without telling which view are coming the plugins from.
  • loadAllAsync: this function creates esta función crea un Promise por cada uno de los plugins declarados en el array plugins mencionado más arriba, llama a loadPluginFile y al finalizar añade a la lista pluginInstancesList la instancia del plugin. Debido a la interrelación existente entre BasePlugin y la definición del plugin (se hacen llamadas a los métodos del otro desde ambas partes) el procedimiento es instanciar un Ediphy.Plugin, instanciar la definición del plugin seleccionado pasando como parámetro el Ediphy.Plugin anterior, asignar la nueva instancia al Ediphy.Plugin original usando el método create y finalmente, asignarla a la lista de instancias pluginInstancesList. Se puede ver el código a continuación:
var plugin = new Ediphy.Plugin();
plugin.create(Ediphy.Plugins[name](plugin));
pluginInstancesList[name] = plugin;

This function returns a new Promise that whit Promises List create before, makes that everything in the method will be asynchronous.

Ediphy.Visor.Plugins

This object exposes the methods to work with the instances list of the plugins in the proper format required by visor and exporter ("visor mode" definition). These are:

  • get: returns the instance which plugin is passed as parameter.

  • getAll: returns instances of every plugin.

  • add: creates new instance of a plugin and adds it to the list. At any given time, there will be only one instance of a plugin; if for some reason this method was called twice by the same plugin, the instance before is overwritten. Recieves as parameter the plugin name. If the definition of the plugin was found for "visor mode", use this to instanciate the plugin, otherwise, use the definition of "editor mode". This is done the same mode as Ediphy.Plugin.

Also, when loading the plugins, its definitions keep saving in this object.

Clone this wiki locally