-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathPlugin.js
31 lines (26 loc) · 1000 Bytes
/
Plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
export default class Plugin {
// can be overwritten if necessary
constructor(map, name, options = {}) {
// TODO error if map and name are undef?
this.map = map;
this.name = name;
this.options = options;
}
async init() {
// Optional, called after the plugin has been constructed
}
async renderMap() {
// Mandatory, the method that modifies/updates the leaflet map itself
throw new Error(`Plugin ${this.name} does not implement a renderMap() method!`, { cause: 'NotImplemented' });
}
async update() {
// Optional, called by the PluginsRenderService.render method
// useful if plugin needs to respond to HA state.
}
destroy() {
// Mandatory. Called from PluginsRenderService.cleanup when the
// MapCard.disconnectedCallback is called. Use this to clean up
// the state, remove listeners, intervals, timers, etc.
throw new Error(`Plugin ${this.name} does not implement a destroy() method!`, { cause: 'NotImplemented' });
}
}