@@ -205,9 +205,10 @@ export const BCarousel = /*#__PURE__*/ Vue.extend({
205205 } ,
206206 created ( ) {
207207 // Create private non-reactive props
208- this . _intervalId = null
209- this . _animationTimeout = null
210- this . _touchTimeout = null
208+ this . $_interval = null
209+ this . $_animationTimeout = null
210+ this . $_touchTimeout = null
211+ this . $_observer = null
211212 // Set initial paused state
212213 this . isPaused = ! ( toInteger ( this . interval , 0 ) > 0 )
213214 } ,
@@ -217,22 +218,39 @@ export const BCarousel = /*#__PURE__*/ Vue.extend({
217218 // Get all slides
218219 this . updateSlides ( )
219220 // Observe child changes so we can update slide list
220- observeDom ( this . $refs . inner , this . updateSlides . bind ( this ) , {
221- subtree : false ,
222- childList : true ,
223- attributes : true ,
224- attributeFilter : [ 'id' ]
225- } )
221+ this . setObserver ( true )
226222 } ,
227223 beforeDestroy ( ) {
228- clearTimeout ( this . _animationTimeout )
229- clearTimeout ( this . _touchTimeout )
230- clearInterval ( this . _intervalId )
231- this . _intervalId = null
232- this . _animationTimeout = null
233- this . _touchTimeout = null
224+ this . clearInterval ( )
225+ this . clearAnimationTimeout ( )
226+ this . clearTouchTimeout ( )
227+ this . setObserver ( false )
234228 } ,
235229 methods : {
230+ clearInterval ( ) {
231+ clearInterval ( this . $_interval )
232+ this . $_interval = null
233+ } ,
234+ clearAnimationTimeout ( ) {
235+ clearTimeout ( this . $_animationTimeout )
236+ this . $_animationTimeout = null
237+ } ,
238+ clearTouchTimeout ( ) {
239+ clearTimeout ( this . $_touchTimeout )
240+ this . $_touchTimeout = null
241+ } ,
242+ setObserver ( on = false ) {
243+ this . $_observer && this . $_observer . disconnect ( )
244+ this . $_observer = null
245+ if ( on ) {
246+ this . $_observer = observeDom ( this . $refs . inner , this . updateSlides . bind ( this ) , {
247+ subtree : false ,
248+ childList : true ,
249+ attributes : true ,
250+ attributeFilter : [ 'id' ]
251+ } )
252+ }
253+ } ,
236254 // Set slide
237255 setSlide ( slide , direction = null ) {
238256 // Don't animate when page is not visible
@@ -286,24 +304,18 @@ export const BCarousel = /*#__PURE__*/ Vue.extend({
286304 if ( ! evt ) {
287305 this . isPaused = true
288306 }
289- if ( this . _intervalId ) {
290- clearInterval ( this . _intervalId )
291- this . _intervalId = null
292- }
307+ this . clearInterval ( )
293308 } ,
294309 // Start auto rotate slides
295310 start ( evt ) {
296311 if ( ! evt ) {
297312 this . isPaused = false
298313 }
299314 /* istanbul ignore next: most likely will never happen, but just in case */
300- if ( this . _intervalId ) {
301- clearInterval ( this . _intervalId )
302- this . _intervalId = null
303- }
315+ this . clearInterval ( )
304316 // Don't start if no interval, or less than 2 slides
305317 if ( this . interval && this . numSlides > 1 ) {
306- this . _intervalId = setInterval ( this . next , mathMax ( 1000 , this . interval ) )
318+ this . $_interval = setInterval ( this . next , mathMax ( 1000 , this . interval ) )
307319 }
308320 } ,
309321 // Restart auto rotate slides when focus/hover leaves the carousel
@@ -362,7 +374,7 @@ export const BCarousel = /*#__PURE__*/ Vue.extend({
362374 eventOff ( currentSlide , evt , onceTransEnd , EVENT_OPTIONS_NO_CAPTURE )
363375 )
364376 }
365- this . _animationTimeout = null
377+ this . clearAnimationTimeout ( )
366378 removeClass ( nextSlide , dirClass )
367379 removeClass ( nextSlide , overlayClass )
368380 addClass ( nextSlide , 'active' )
@@ -387,7 +399,7 @@ export const BCarousel = /*#__PURE__*/ Vue.extend({
387399 )
388400 }
389401 // Fallback to setTimeout()
390- this . _animationTimeout = setTimeout ( onceTransEnd , TRANS_DURATION )
402+ this . $ _animationTimeout = setTimeout ( onceTransEnd , TRANS_DURATION )
391403 }
392404 if ( isCycling ) {
393405 this . start ( false )
@@ -480,10 +492,8 @@ export const BCarousel = /*#__PURE__*/ Vue.extend({
480492 // is NOT fired) and after a timeout (to allow for mouse compatibility
481493 // events to fire) we explicitly restart cycling
482494 this . pause ( false )
483- if ( this . _touchTimeout ) {
484- clearTimeout ( this . _touchTimeout )
485- }
486- this . _touchTimeout = setTimeout (
495+ this . clearTouchTimeout ( )
496+ this . $_touchTimeout = setTimeout (
487497 this . start ,
488498 TOUCH_EVENT_COMPAT_WAIT + mathMax ( 1000 , this . interval )
489499 )
0 commit comments