Created
February 16, 2014 00:20
-
-
Save tuxracer/9027318 to your computer and use it in GitHub Desktop.
Revisions
-
tuxracer created this gist
Feb 16, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ # Using @setTimeout or @setInterval will clear the timers on dispose # Mixin, can be used with https://github.com/HubSpot/mixen start = (type, args) -> unless @disposed method = window["set#{type}"] timer = method.apply window, args @timers[type].push timer timer module.exports = class StopTimers constructor: -> @resetTimers() super resetTimers: -> @timers = Interval: [] Timeout: [] setInterval: -> start.call @, 'Interval', arguments setTimeout: -> start.call @, 'Timeout', arguments dispose: -> for key, val of @timers clearMethod = window["clear#{key}"] val.forEach clearMethod @resetTimers() super