mirror of
				https://github.com/twbs/bootstrap.git
				synced 2022-11-09 12:25:43 -05:00 
			
		
		
		
	Carousel: move repeated code to a method
This commit is contained in:
		
							parent
							
								
									b8ee68cfa0
								
							
						
					
					
						commit
						0d4213bde3
					
				
					 2 changed files with 15 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -148,8 +148,7 @@ class Carousel extends BaseComponent {
 | 
			
		|||
      this.cycle(true)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    clearInterval(this._interval)
 | 
			
		||||
    this._interval = null
 | 
			
		||||
    this._clearInterval()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  cycle(event) {
 | 
			
		||||
| 
						 | 
				
			
			@ -157,11 +156,7 @@ class Carousel extends BaseComponent {
 | 
			
		|||
      this._isPaused = false
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (this._interval) {
 | 
			
		||||
      clearInterval(this._interval)
 | 
			
		||||
      this._interval = null
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    this._clearInterval()
 | 
			
		||||
    if (this._config.interval && !this._isPaused) {
 | 
			
		||||
      this._updateInterval()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -412,6 +407,13 @@ class Carousel extends BaseComponent {
 | 
			
		|||
    return SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  _clearInterval() {
 | 
			
		||||
    if (this._interval) {
 | 
			
		||||
      clearInterval(this._interval)
 | 
			
		||||
      this._interval = null
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  _directionToOrder(direction) {
 | 
			
		||||
    if (![DIRECTION_RIGHT, DIRECTION_LEFT].includes(direction)) {
 | 
			
		||||
      return direction
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -851,12 +851,12 @@ describe('Carousel', () => {
 | 
			
		|||
      const carousel = new Carousel(carouselEl)
 | 
			
		||||
 | 
			
		||||
      spyOn(carousel, 'cycle')
 | 
			
		||||
      spyOn(window, 'clearInterval')
 | 
			
		||||
      spyOn(carousel, '_clearInterval')
 | 
			
		||||
 | 
			
		||||
      carousel.pause()
 | 
			
		||||
 | 
			
		||||
      expect(carousel.cycle).toHaveBeenCalledWith(true)
 | 
			
		||||
      expect(window.clearInterval).toHaveBeenCalled()
 | 
			
		||||
      expect(carousel._clearInterval).toHaveBeenCalled()
 | 
			
		||||
      expect(carousel._isPaused).toBeTrue()
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -877,12 +877,12 @@ describe('Carousel', () => {
 | 
			
		|||
      const carousel = new Carousel(carouselEl)
 | 
			
		||||
 | 
			
		||||
      spyOn(carousel, 'cycle')
 | 
			
		||||
      spyOn(window, 'clearInterval')
 | 
			
		||||
      spyOn(carousel, '_clearInterval')
 | 
			
		||||
 | 
			
		||||
      carousel.pause()
 | 
			
		||||
 | 
			
		||||
      expect(carousel.cycle).not.toHaveBeenCalled()
 | 
			
		||||
      expect(window.clearInterval).toHaveBeenCalled()
 | 
			
		||||
      expect(carousel._clearInterval).toHaveBeenCalled()
 | 
			
		||||
      expect(carousel._isPaused).toBeTrue()
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -903,11 +903,11 @@ describe('Carousel', () => {
 | 
			
		|||
      const carousel = new Carousel(carouselEl)
 | 
			
		||||
      const event = createEvent('mouseenter')
 | 
			
		||||
 | 
			
		||||
      spyOn(window, 'clearInterval')
 | 
			
		||||
      spyOn(carousel, '_clearInterval')
 | 
			
		||||
 | 
			
		||||
      carousel.pause(event)
 | 
			
		||||
 | 
			
		||||
      expect(window.clearInterval).toHaveBeenCalled()
 | 
			
		||||
      expect(carousel._clearInterval).toHaveBeenCalled()
 | 
			
		||||
      expect(carousel._isPaused).toBeFalse()
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue