Skip to content

Commit 9a0bba9

Browse files
authored
Object spread : less jQuery more ES6 (#24665)
1 parent 1354a92 commit 9a0bba9

File tree

9 files changed

+86
-52
lines changed

9 files changed

+86
-52
lines changed

.babelrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
]
1111
],
1212
plugins: [
13-
process.env.PLUGINS && 'transform-es2015-modules-strip'
13+
process.env.PLUGINS && 'transform-es2015-modules-strip',
14+
'@babel/proposal-object-rest-spread'
1415
].filter(Boolean)
1516
};

build/rollup.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const plugins = [
1515
externalHelpersWhitelist: [ // include only required helpers
1616
'defineProperties',
1717
'createClass',
18-
'inheritsLoose'
18+
'inheritsLoose',
19+
'extends'
1920
]
2021
})
2122
]

js/src/carousel.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ const Carousel = (($) => {
223223
// private
224224

225225
_getConfig(config) {
226-
config = $.extend({}, Default, config)
226+
config = {
227+
...Default,
228+
...config
229+
}
227230
Util.typeCheckConfig(NAME, config, DefaultType)
228231
return config
229232
}
@@ -428,10 +431,16 @@ const Carousel = (($) => {
428431
static _jQueryInterface(config) {
429432
return this.each(function () {
430433
let data = $(this).data(DATA_KEY)
431-
const _config = $.extend({}, Default, $(this).data())
434+
let _config = {
435+
...Default,
436+
...$(this).data()
437+
}
432438

433439
if (typeof config === 'object') {
434-
$.extend(_config, config)
440+
_config = {
441+
..._config,
442+
...config
443+
}
435444
}
436445

437446
const action = typeof config === 'string' ? config : _config.slide
@@ -468,7 +477,10 @@ const Carousel = (($) => {
468477
return
469478
}
470479

471-
const config = $.extend({}, $(target).data(), $(this).data())
480+
const config = {
481+
...$(target).data(),
482+
...$(this).data()
483+
}
472484
const slideIndex = this.getAttribute('data-slide-to')
473485

474486
if (slideIndex) {

js/src/collapse.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ const Collapse = (($) => {
277277
// private
278278

279279
_getConfig(config) {
280-
config = $.extend({}, Default, config)
280+
config = {
281+
...Default,
282+
...config
283+
}
281284
config.toggle = Boolean(config.toggle) // coerce string values
282285
Util.typeCheckConfig(NAME, config, DefaultType)
283286
return config
@@ -338,12 +341,11 @@ const Collapse = (($) => {
338341
return this.each(function () {
339342
const $this = $(this)
340343
let data = $this.data(DATA_KEY)
341-
const _config = $.extend(
342-
{},
343-
Default,
344-
$this.data(),
345-
typeof config === 'object' && config
346-
)
344+
const _config = {
345+
...Default,
346+
...$this.data(),
347+
...typeof config === 'object' && config
348+
}
347349

348350
if (!data && _config.toggle && /show|hide/.test(config)) {
349351
_config.toggle = false

js/src/dropdown.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,11 @@ const Dropdown = (($) => {
210210
}
211211

212212
_getConfig(config) {
213-
config = $.extend(
214-
{},
215-
this.constructor.Default,
216-
$(this._element).data(),
217-
config
218-
)
213+
config = {
214+
...this.constructor.Default,
215+
...$(this._element).data(),
216+
...config
217+
}
219218

220219
Util.typeCheckConfig(
221220
NAME,
@@ -262,7 +261,10 @@ const Dropdown = (($) => {
262261
const offsetConf = {}
263262
if (typeof this._config.offset === 'function') {
264263
offsetConf.fn = (data) => {
265-
data.offsets = $.extend({}, data.offsets, this._config.offset(data.offsets) || {})
264+
data.offsets = {
265+
...data.offsets,
266+
...this._config.offset(data.offsets) || {}
267+
}
266268
return data
267269
}
268270
} else {

js/src/modal.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ const Modal = (($) => {
227227
// private
228228

229229
_getConfig(config) {
230-
config = $.extend({}, Default, config)
230+
config = {
231+
...Default,
232+
...config
233+
}
231234
Util.typeCheckConfig(NAME, config, DefaultType)
232235
return config
233236
}
@@ -506,12 +509,11 @@ const Modal = (($) => {
506509
static _jQueryInterface(config, relatedTarget) {
507510
return this.each(function () {
508511
let data = $(this).data(DATA_KEY)
509-
const _config = $.extend(
510-
{},
511-
Modal.Default,
512-
$(this).data(),
513-
typeof config === 'object' && config
514-
)
512+
const _config = {
513+
...Modal.Default,
514+
...$(this).data(),
515+
...typeof config === 'object' && config
516+
}
515517

516518
if (!data) {
517519
data = new Modal(this, _config)
@@ -547,7 +549,10 @@ const Modal = (($) => {
547549
}
548550

549551
const config = $(target).data(DATA_KEY) ?
550-
'toggle' : $.extend({}, $(target).data(), $(this).data())
552+
'toggle' : {
553+
...$(target).data(),
554+
...$(this).data()
555+
}
551556

552557
if (this.tagName === 'A' || this.tagName === 'AREA') {
553558
event.preventDefault()

js/src/popover.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@ const Popover = (($) => {
2626
const CLASS_PREFIX = 'bs-popover'
2727
const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
2828

29-
const Default = $.extend({}, Tooltip.Default, {
30-
placement : 'right',
31-
trigger : 'click',
32-
content : '',
33-
template : '<div class="popover" role="tooltip">'
34-
+ '<div class="arrow"></div>'
35-
+ '<h3 class="popover-header"></h3>'
36-
+ '<div class="popover-body"></div></div>'
37-
})
38-
39-
const DefaultType = $.extend({}, Tooltip.DefaultType, {
40-
content : '(string|element|function)'
41-
})
29+
const Default = {
30+
...Tooltip.Default,
31+
...{
32+
placement : 'right',
33+
trigger : 'click',
34+
content : '',
35+
template : '<div class="popover" role="tooltip">'
36+
+ '<div class="arrow"></div>'
37+
+ '<h3 class="popover-header"></h3>'
38+
+ '<div class="popover-body"></div></div>'
39+
}
40+
}
41+
42+
const DefaultType = {
43+
...Tooltip.DefaultType,
44+
...{
45+
content : '(string|element|function)'
46+
}
47+
}
4248

4349
const ClassName = {
4450
FADE : 'fade',

js/src/scrollspy.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ const ScrollSpy = (($) => {
171171
// private
172172

173173
_getConfig(config) {
174-
config = $.extend({}, Default, config)
174+
config = {
175+
...Default,
176+
...config
177+
}
175178

176179
if (typeof config.target !== 'string') {
177180
let id = $(config.target).attr('id')

js/src/tooltip.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,13 @@ const Tooltip = (($) => {
501501
})
502502

503503
if (this.config.selector) {
504-
this.config = $.extend({}, this.config, {
505-
trigger : 'manual',
506-
selector : ''
507-
})
504+
this.config = {
505+
...this.config,
506+
...{
507+
trigger : 'manual',
508+
selector : ''
509+
}
510+
}
508511
} else {
509512
this._fixTitle()
510513
}
@@ -613,12 +616,11 @@ const Tooltip = (($) => {
613616
}
614617

615618
_getConfig(config) {
616-
config = $.extend(
617-
{},
618-
this.constructor.Default,
619-
$(this.element).data(),
620-
config
621-
)
619+
config = {
620+
...this.constructor.Default,
621+
...$(this.element).data(),
622+
...config
623+
}
622624

623625
if (typeof config.delay === 'number') {
624626
config.delay = {

0 commit comments

Comments
 (0)