Add new file
This commit is contained in:
parent
d58fba7c25
commit
e0fea221d0
50
docs/plugin.md
Normal file
50
docs/plugin.md
Normal 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);
|
||||
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user