-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinternalPluginSkeleton.js
100 lines (84 loc) · 3.24 KB
/
internalPluginSkeleton.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// You need to import the BasePlugin class in order to inherit from it.
import BasePlugin from './../../_base';
import {registerPlugin} from './../../../plugins';
/**
* @plugin InternalPluginSkeleton
* Note: keep in mind, that Handsontable instance creates one instance of the plugin class.
*
* @description
* Blank plugin template. It needs to inherit from the BasePlugin class.
*/
class InternalPluginSkeleton extends BasePlugin {
// The argument passed to the constructor is the currently processed Handsontable instance object.
constructor(hotInstance) {
super(hotInstance);
// Initialize all your public properties in the class' constructor.
/**
* yourProperty description.
*
* @type {String}
*/
this.yourProperty = '';
/**
* anotherProperty description.
* @type {Array}
*/
this.anotherProperty = [];
}
/**
* Checks if the plugin is enabled in the settings.
*/
isEnabled() {
return !!this.hot.getSettings().internalPluginSkeleton;
}
/**
* The enablePlugin method is triggered on the beforeInit hook. It should contain your initial plugin setup, along with
* the hook connections.
* Note, that this method is run only if the statement in the isEnabled method is true.
*/
enablePlugin() {
this.yourProperty = 'Your Value';
// Add all your plugin hooks here. It's a good idea to make use of the arrow functions to keep the context consistent.
this.addHook('afterChange', (changes, source) => this.onAfterChange(changes, source));
// The super method assigns the this.enabled property to true, which can be later used to check if plugin is already enabled.
super.enablePlugin();
}
/**
* The disablePlugin method is used to disable the plugin. Reset all of your classes properties to their default values here.
*/
disablePlugin() {
this.yourProperty = '';
this.anotherProperty = [];
// The super method takes care of clearing the hook connections and assigning the 'false' value to the 'this.enabled' property.
super.disablePlugin();
}
/**
* The updatePlugin method is called on the afterUpdateSettings hook (unless the updateSettings method turned the plugin off).
* It should contain all the stuff your plugin needs to do to work properly after the Handsontable instance settings were modified.
*/
updatePlugin() {
// The updatePlugin method needs to contain all the code needed to properly re-enable the plugin. In most cases simply disabling and enabling the plugin should do the trick.
this.disablePlugin();
this.enablePlugin();
super.updatePlugin();
}
/**
* The afterChange hook callback.
*
* @param {Array} changes Array of changes.
* @param {String} source Describes the source of the change.
*/
onAfterChange(changes, source) {
// afterChange callback goes here.
}
/**
* The destroy method should de-assign all of your properties.
*/
destroy() {
// The super method takes care of de-assigning the event callbacks, plugin hooks and clearing all the plugin properties.
super.destroy();
}
}
export {InternalPluginSkeleton};
// You need to register your plugin in order to use it within Handsontable.
registerPlugin('internalPluginSkeleton', InternalPluginSkeleton);