Add new file

This commit is contained in:
Roni Lehto 2021-04-07 21:11:48 +00:00
parent d58fba7c25
commit e0fea221d0

50
docs/plugin.md Normal file
View File

@ -0,0 +1,50 @@
# Plugins
Here is a brief specification of the plugin module itself.
All loadable plugin modules need to have an `init` method.
## Backend
Backend modules get two initialization parameters: `logger` and `LMathPluginAPI`.
Feel free to use these in any way you want. Below you'll find a simple example.
```js
let logger, api;
module.exports = {
init: (_logger, _api) => {
logger = _logger;
api = _api;
logger.info('Hewwo! It is me, the new plugin!');
api.messages.on('testMessage', (d) => {
logger.info('Someone sent me a message! ' + d);
});
}
};
```
## Frontend
Frontend modules also get two parameters: `window` (the actual window object) and `LMathPluginAPI` (frontend).
jQuery and other useful things can be found like presented below.
```js
let window, api, $, jQuery;
module.exports = {
init: (_window, _api) => {
window = _window;
api = _api;
$ = window.jQuery;
jQuery = window.jQuery;
console.log('Hewwo wowld! This is the frontend side!');
setInterval(() => api.messages.send('testMessage', Date.now()), 2000);
}
}
```