From 59a070bf841f6be296e067efc7458ffede649f47 Mon Sep 17 00:00:00 2001 From: Jari Bakken Date: Fri, 24 Oct 2014 13:57:08 +0200 Subject: [PATCH] Add a Timer that can be stopped while requests are pending. --- unleash-server/public/js/unleash.jsx | 38 ++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/unleash-server/public/js/unleash.jsx b/unleash-server/public/js/unleash.jsx index b20b736d34..b747de3f76 100644 --- a/unleash-server/public/js/unleash.jsx +++ b/unleash-server/public/js/unleash.jsx @@ -8,6 +8,31 @@ // - SavedFeature // +var Timer = function(cb, interval) { + this.cb = cb; + this.interval = interval; + this.timerId = null; +}; + +Timer.prototype.start = function() { + if (this.timerId != null) { + console.warn("timer already started"); + } + + console.log('starting timer'); + this.timerId = setInterval(this.cb, this.interval); +}; + +Timer.prototype.stop = function() { + if (this.timerId == null) { + console.warn('no timer running'); + } else { + console.log('stopping timer'); + clearInterval(this.timerId); + this.timerId = null; + } +}; + var Menu = React.createClass({ render: function() { return (