Skip to content
Permalink
Browse files
fix(b-alert): memory leak by using the correct method to clear the co…
…untdown timeout (#5158)
  • Loading branch information
jacobmllr95 committed Apr 16, 2020
1 parent f544bd5 commit 7a7f33d74f906e5feecf2bf177636c7f85bc4537
Showing 1 changed file with 9 additions and 9 deletions.
@@ -65,8 +65,8 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
},
data() {
return {
countDownTimerId: null,
countDown: 0,
countDownTimeout: null,
// If initially shown, we need to set these for SSR
localShow: parseShow(this.show)
}
@@ -77,7 +77,7 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
this.localShow = parseShow(newVal)
},
countDown(newVal) {
this.clearTimer()
this.clearCountDownInterval()
if (isNumericLike(this.show)) {
// Ignore if this.show transitions to a boolean value.
this.$emit('dismiss-count-down', newVal)
@@ -87,7 +87,7 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
}
if (newVal > 0) {
this.localShow = true
this.countDownTimerId = setTimeout(() => {
this.countDownTimeout = setTimeout(() => {
this.countDown--
}, 1000)
} else {
@@ -120,18 +120,18 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
this.localShow = parseShow(this.show)
},
beforeDestroy() {
this.clearTimer()
this.clearCountDownInterval()
},
methods: {
dismiss() {
this.clearTimer()
this.clearCountDownInterval()
this.countDown = 0
this.localShow = false
},
clearTimer() {
if (this.countDownTimerId) {
clearInterval(this.countDownTimerId)
this.countDownTimerId = null
clearCountDownInterval() {
if (this.countDownTimeout) {
clearTimeout(this.countDownTimeout)
this.countDownTimeout = null
}
}
},

0 comments on commit 7a7f33d

Please sign in to comment.