Skip to content

Commit 61b75dc

Browse files
authored
feat(utils/noop): add noop() util (#2892)
* feat(utils/noop): add `noop()` util * fix noop reference
1 parent cbd0708 commit 61b75dc

File tree

3 files changed

+53
-61
lines changed

3 files changed

+53
-61
lines changed

src/components/carousel/carousel.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import observeDom from '../../utils/observe-dom'
22
import KeyCodes from '../../utils/key-codes'
3+
import noop from '../../utils/noop'
34
import {
45
selectAll,
56
reflow,
@@ -28,7 +29,7 @@ const DIRECTION = {
2829
const TRANS_DURATION = 600 + 50
2930

3031
// Time for mouse compat events to fire after touch
31-
const TOUCHEVENT_COMPAT_WAIT = 500
32+
const TOUCH_EVENT_COMPAT_WAIT = 500
3233

3334
// Number of pixels to consider touch move a swipe
3435
const SWIPE_THRESHOLD = 40
@@ -50,7 +51,7 @@ const TransitionEndEvents = {
5051
const EventOptions = { passive: true, capture: false }
5152

5253
// Return the browser specific transitionEnd event name
53-
function getTransisionEndEvent(el) {
54+
function getTransitionEndEvent(el) {
5455
for (const name in TransitionEndEvents) {
5556
if (el.style[name] !== undefined) {
5657
return TransitionEndEvents[name]
@@ -61,8 +62,6 @@ function getTransisionEndEvent(el) {
6162
return null
6263
}
6364

64-
const noop = () => {}
65-
6665
// @vue/component
6766
export default {
6867
name: 'BCarousel',
@@ -194,7 +193,7 @@ export default {
194193
},
195194
mounted() {
196195
// Cache current browser transitionend event name
197-
this.transitionEndEvent = getTransisionEndEvent(this.$el) || null
196+
this.transitionEndEvent = getTransitionEndEvent(this.$el) || null
198197
// Get all slides
199198
this.updateSlides()
200199
// Observe child changes so we can update slide list
@@ -205,7 +204,7 @@ export default {
205204
attributeFilter: ['id']
206205
})
207206
},
208-
beforeDestroy() /* istanbul ignore next: dificult to test */ {
207+
beforeDestroy() /* istanbul ignore next: difficult to test */ {
209208
clearTimeout(this._animationTimeout)
210209
clearTimeout(this._touchTimeout)
211210
clearInterval(this._intervalId)
@@ -217,7 +216,7 @@ export default {
217216
// Set slide
218217
setSlide(slide, direction = null) {
219218
// Don't animate when page is not visible
220-
/* istanbul ignore if: dificult to test */
219+
/* istanbul ignore if: difficult to test */
221220
if (inBrowser && document.visibilityState && document.hidden) {
222221
return
223222
}
@@ -261,7 +260,7 @@ export default {
261260
if (!evt) {
262261
this.isPaused = false
263262
}
264-
/* istanbul ignore next: most likley will never happen, but just in case */
263+
/* istanbul ignore next: most likely will never happen, but just in case */
265264
if (this._intervalId) {
266265
clearInterval(this._intervalId)
267266
this._intervalId = null
@@ -271,9 +270,9 @@ export default {
271270
this._intervalId = setInterval(this.next, Math.max(1000, this.interval))
272271
}
273272
},
274-
// Re-Start auto rotate slides when focus/hover leaves the carousel
273+
// Restart auto rotate slides when focus/hover leaves the carousel
275274
restart(evt) {
276-
/* istanbul ignore if: dificult to test */
275+
/* istanbul ignore if: difficult to test */
277276
if (!this.$el.contains(document.activeElement)) {
278277
this.start()
279278
}
@@ -314,7 +313,7 @@ export default {
314313
addClass(nextSlide, dirClass)
315314
// Transition End handler
316315
let called = false
317-
/* istanbul ignore next: dificult to test */
316+
/* istanbul ignore next: difficult to test */
318317
const onceTransEnd = evt => {
319318
if (called) {
320319
return
@@ -347,7 +346,7 @@ export default {
347346
const events = this.transitionEndEvent.split(/\s+/)
348347
events.forEach(event => eventOn(currentSlide, event, onceTransEnd, EventOptions))
349348
}
350-
// Fallback to setTimeout
349+
// Fallback to setTimeout()
351350
this._animationTimeout = setTimeout(onceTransEnd, TRANS_DURATION)
352351
}
353352
if (isCycling) {
@@ -393,16 +392,16 @@ export default {
393392
}
394393
},
395394
handleSwipe() /* istanbul ignore next: JSDOM doesn't support touch events */ {
396-
const absDeltax = Math.abs(this.touchDeltaX)
397-
if (absDeltax <= SWIPE_THRESHOLD) {
395+
const absDeltaX = Math.abs(this.touchDeltaX)
396+
if (absDeltaX <= SWIPE_THRESHOLD) {
398397
return
399398
}
400-
const direction = absDeltax / this.touchDeltaX
399+
const direction = absDeltaX / this.touchDeltaX
401400
if (direction > 0) {
402-
// swipe left
401+
// Swipe left
403402
this.prev()
404403
} else if (direction < 0) {
405-
// swipe right
404+
// Swipe right
406405
this.next()
407406
}
408407
},
@@ -414,7 +413,7 @@ export default {
414413
}
415414
},
416415
touchMove(evt) /* istanbul ignore next: JSDOM doesn't support touch events */ {
417-
// ensure swiping with one touch and not pinching
416+
// Ensure swiping with one touch and not pinching
418417
if (evt.touches && evt.touches.length > 1) {
419418
this.touchDeltaX = 0
420419
} else {
@@ -439,7 +438,7 @@ export default {
439438
}
440439
this._touchTimeout = setTimeout(
441440
this.start,
442-
TOUCHEVENT_COMPAT_WAIT + Math.max(1000, this.interval)
441+
TOUCH_EVENT_COMPAT_WAIT + Math.max(1000, this.interval)
443442
)
444443
}
445444
},
@@ -458,7 +457,7 @@ export default {
458457
[this.$slots.default]
459458
)
460459

461-
// Prev and Next Controls
460+
// Prev and next controls
462461
let controls = h(false)
463462
if (this.controls) {
464463
controls = [
@@ -567,7 +566,8 @@ export default {
567566
}
568567
// Touch support event handlers for environment
569568
if (!this.noTouch && hasTouchSupport) {
570-
/* istanbul ignore next: JSDOM doesn't support touch events */ // Attach appropriate listeners (passsive mode)
569+
// Attach appropriate listeners (passive mode)
570+
/* istanbul ignore next: JSDOM doesn't support touch events */
571571
if (hasPointerEvent) {
572572
on['&pointerdown'] = this.touchStart
573573
on['&pointerup'] = this.touchEnd

src/utils/noop.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const noop = () => {}
2+
3+
export default noop

0 commit comments

Comments
 (0)