Skip to content

Commit

Permalink
Merge pull request #77 from suresh-gangumalla/feat/clear-all
Browse files Browse the repository at this point in the history
Added clearIntervals & clearTimeouts functions
  • Loading branch information
michielvandergeest authored Mar 1, 2024
2 parents 630635b + f29d20d commit ebfb9f6
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/lib/setup/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,8 @@ export default (component, name) => {
destroy: {
value: function () {
this.lifecycle.state = 'destroy'
for (let i = 0; i < this[symbols.timeouts].length; i++) {
clearTimeout(this[symbols.timeouts][i])
}
for (let i = 0; i < this[symbols.intervals].length; i++) {
clearInterval(this[symbols.intervals][i])
}
this.$clearTimeouts()
this.$clearIntervals()
eventListeners.removeListeners(this)
deleteChildren(this[symbols.children])
Log.debug(`Destroyed component ${this.componentId}`)
Expand Down Expand Up @@ -176,6 +172,17 @@ export default (component, name) => {
enumerable: true,
configurable: false,
},
$clearTimeouts: {
value: function () {
for (let i = 0; i < this[symbols.timeouts].length; i++) {
clearTimeout(this[symbols.timeouts][i])
}
this[symbols.timeouts] = []
},
writable: false,
enumerable: true,
configurable: false,
},
$setInterval: {
value: function (fn, ms, ...params) {
const intervalId = setInterval(() => fn.apply(null, params), ms, params)
Expand All @@ -197,6 +204,17 @@ export default (component, name) => {
enumerable: true,
configurable: false,
},
$clearIntervals: {
value: function () {
for (let i = 0; i < this[symbols.intervals].length; i++) {
clearInterval(this[symbols.intervals][i])
}
this[symbols.intervals] = []
},
writable: false,
enumerable: true,
configurable: false,
},
$emit: {
value: function (event, params) {
eventListeners.executeListeners(event, params)
Expand Down

0 comments on commit ebfb9f6

Please sign in to comment.