aboutsummaryrefslogtreecommitdiff
path: root/js/src/base-component.js
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2021-05-11 10:49:30 +0300
committerGitHub <[email protected]>2021-05-11 10:49:30 +0300
commit9fe36edf683af02574bf6bbd6c9b27de93bd31b1 (patch)
tree111d2b788e990a58277ff4543cfd44c5815ac795 /js/src/base-component.js
parent7647b8fe5b77120ba319e7119bb0515d91f734da (diff)
downloadbootstrap-9fe36edf683af02574bf6bbd6c9b27de93bd31b1.tar.xz
bootstrap-9fe36edf683af02574bf6bbd6c9b27de93bd31b1.zip
Extract static `DATA_KEY` & `EVENT_KEY` to base-component (#33635)
* Force each plugin that extends base-components to implement a static method `NAME()` * Remove redundant `NAME` argument from 'Utils.defineJQueryPlugin' & fix test
Diffstat (limited to 'js/src/base-component.js')
-rw-r--r--js/src/base-component.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/js/src/base-component.js b/js/src/base-component.js
index 588a59d75..eacc8420b 100644
--- a/js/src/base-component.js
+++ b/js/src/base-component.js
@@ -35,7 +35,7 @@ class BaseComponent {
dispose() {
Data.remove(this._element, this.constructor.DATA_KEY)
- EventHandler.off(this._element, `.${this.constructor.DATA_KEY}`)
+ EventHandler.off(this._element, this.constructor.EVENT_KEY)
Object.getOwnPropertyNames(this).forEach(propertyName => {
this[propertyName] = null
@@ -63,6 +63,18 @@ class BaseComponent {
static get VERSION() {
return VERSION
}
+
+ static get NAME() {
+ throw new Error('You have to implement the static method "NAME", for each component!')
+ }
+
+ static get DATA_KEY() {
+ return `bs.${this.NAME}`
+ }
+
+ static get EVENT_KEY() {
+ return `.${this.DATA_KEY}`
+ }
}
export default BaseComponent