diff options
| author | GeoSot <[email protected]> | 2021-12-10 18:18:18 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-10 18:18:18 +0200 |
| commit | 886b940796b3595a03b44230ca8b78197c5ee1c5 (patch) | |
| tree | 6b37d0208ae9fd9816e052572ab3496095cc88b6 /js/src/base-component.js | |
| parent | 68f226750db03bc26ed5ead6bb074804a4f63853 (diff) | |
| download | bootstrap-886b940796b3595a03b44230ca8b78197c5ee1c5.tar.xz bootstrap-886b940796b3595a03b44230ca8b78197c5ee1c5.zip | |
Extract Component config functionality to a separate class (#33872)
Co-authored-by: XhmikosR <[email protected]>
Diffstat (limited to 'js/src/base-component.js')
| -rw-r--r-- | js/src/base-component.js | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/js/src/base-component.js b/js/src/base-component.js index 3c5eb460a..4140bf194 100644 --- a/js/src/base-component.js +++ b/js/src/base-component.js @@ -6,11 +6,9 @@ */ import Data from './dom/data' -import { - executeAfterTransition, - getElement -} from './util/index' +import { executeAfterTransition, getElement } from './util/index' import EventHandler from './dom/event-handler' +import Config from './util/config' /** * Constants @@ -22,15 +20,18 @@ const VERSION = '5.1.3' * Class definition */ -class BaseComponent { - constructor(element) { - element = getElement(element) +class BaseComponent extends Config { + constructor(element, config) { + super() + element = getElement(element) if (!element) { return } this._element = element + this._config = this._getConfig(config) + Data.set(this._element, this.constructor.DATA_KEY, this) } @@ -48,6 +49,13 @@ class BaseComponent { executeAfterTransition(callback, element, isAnimated) } + _getConfig(config) { + config = this._mergeConfigObj(config, this._element) + config = this._configAfterMerge(config) + this._typeCheckConfig(config) + return config + } + // Static static getInstance(element) { return Data.get(getElement(element), this.DATA_KEY) @@ -61,10 +69,6 @@ class BaseComponent { 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}` } |
