mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-07 14:16:47 +02:00
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
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user