}
this._element = element
- this._config = this._getConfig(config)
+ this.setConfig(this._getInitialConfig(config))
Data.set(this._element, this.constructor.DATA_KEY, this)
}
executeAfterTransition(callback, element, isAnimated)
}
- _getConfig(config) {
+ _getInitialConfig(config) {
config = this._mergeConfigObj(config, this._element)
config = this._configAfterMerge(config)
this._typeCheckConfig(config)
EventHandler.trigger(this._element, EVENT_HIDDEN, relatedTarget)
}
- _getConfig(config) {
- config = super._getConfig(config)
+ _getInitialConfig(config) {
+ config = super._getInitialConfig(config)
if (typeof config.reference === 'object' && !isElement(config.reference) &&
typeof config.reference.getBoundingClientRect !== 'function'
return Object.values(this._activeTrigger).includes(true)
}
- _getConfig(config) {
+ _getInitialConfig(config) {
const dataAttributes = Manipulator.getDataAttributes(this._element)
for (const dataAttribute of Object.keys(dataAttributes)) {
class Backdrop extends Config {
constructor(config) {
super()
- this._config = this._getConfig(config)
+ this.setConfig(this._getInitialConfig(config))
this._isAppended = false
this._element = null
}
*/
class Config {
+ _config = {}
+
// Getters
static get Default() {
return {}
throw new Error('You have to implement the static method "NAME", for each component!')
}
- _getConfig(config) {
+ setConfig(config) {
+ this._typeCheckConfig(config)
+ this._config = {
+ ...this._config,
+ ...(typeof config === 'object' ? config : {})
+ }
+ }
+
+ _getInitialConfig(config) {
config = this._mergeConfigObj(config)
config = this._configAfterMerge(config)
- this._typeCheckConfig(config)
return config
}
class FocusTrap extends Config {
constructor(config) {
super()
- this._config = this._getConfig(config)
+ this.setConfig(this._getInitialConfig(config))
this._isActive = false
this._lastTabNavDirection = null
}
return
}
- this._config = this._getConfig(config)
+ this.setConfig(this._getInitialConfig(config))
this._deltaX = 0
this._supportPointerEvents = Boolean(window.PointerEvent)
this._initEvents()
class TemplateFactory extends Config {
constructor(config) {
super()
- this._config = this._getConfig(config)
+ this.setConfig(this._getInitialConfig(config))
}
// Getters
})
})
+ describe('setConfig', () => {
+ it('should merge config object', () => {
+ const instance = new DummyConfigClass()
+
+ spyOnProperty(DummyConfigClass, 'DefaultType', 'get').and.returnValue({
+ testBool: 'boolean',
+ testString: 'string'
+ })
+
+ instance.setConfig({
+ testBool: true,
+ testString: 'foo'
+ })
+
+ expect(instance._config.testBool).toBeTrue()
+ expect(instance._config.testString).toEqual('foo')
+
+ instance.setConfig({
+ testBool: false,
+ testString: 'bar'
+ })
+
+ expect(instance._config.testBool).toBeFalse()
+ expect(instance._config.testString).toEqual('bar')
+ })
+
+ it('should check values before merging them', () => {
+ const instance = new DummyConfigClass()
+
+ spyOnProperty(DummyConfigClass, 'DefaultType', 'get').and.returnValue({
+ testBool: 'boolean',
+ testString: 'string'
+ })
+
+ expect(() => {
+ instance.setConfig({
+ testBool: 'foo',
+ testString: true
+ })
+ }).toThrowError(TypeError)
+ })
+ })
+
describe('mergeConfigObj', () => {
it('should parse element\'s data attributes and merge it with default config. Element\'s data attributes must excel Defaults', () => {
fixtureEl.innerHTML = '<div id="test" data-bs-test-bool="false" data-bs-test-int="8" data-bs-test-string1="bar"></div>'