mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
Add a Timer that can be stopped while requests are pending.
This commit is contained in:
parent
835a85db56
commit
edfa9569e7
@ -8,6 +8,31 @@
|
|||||||
// - SavedFeature
|
// - 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({
|
var Menu = React.createClass({
|
||||||
render: function() { return (
|
render: function() { return (
|
||||||
<nav className='navbar navbar-default' role='navigation'>
|
<nav className='navbar navbar-default' role='navigation'>
|
||||||
@ -19,7 +44,6 @@ var Menu = React.createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var UnsavedFeature = React.createClass({
|
var UnsavedFeature = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
@ -152,7 +176,6 @@ var FeatureList = React.createClass({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var ErrorMessages = React.createClass({
|
var ErrorMessages = React.createClass({
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
if (!this.props.errors.length) {
|
if (!this.props.errors.length) {
|
||||||
return <div/>;
|
return <div/>;
|
||||||
@ -175,13 +198,15 @@ var Unleash = React.createClass({
|
|||||||
return {
|
return {
|
||||||
savedFeatures: [],
|
savedFeatures: [],
|
||||||
unsavedFeatures: [],
|
unsavedFeatures: [],
|
||||||
errors: []
|
errors: [],
|
||||||
|
poller: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount: function () {
|
componentDidMount: function () {
|
||||||
this.loadFeaturesFromServer();
|
this.loadFeaturesFromServer();
|
||||||
setInterval(this.loadFeaturesFromServer, this.props.pollInterval);
|
this.state.timer = new Timer(this.loadFeaturesFromServer, this.props.pollInterval);
|
||||||
|
this.state.timer.start();
|
||||||
},
|
},
|
||||||
|
|
||||||
loadFeaturesFromServer: function () {
|
loadFeaturesFromServer: function () {
|
||||||
@ -205,6 +230,7 @@ var Unleash = React.createClass({
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.setState({features: newFeatures});
|
this.setState({features: newFeatures});
|
||||||
|
this.state.timer.stop();
|
||||||
|
|
||||||
reqwest({
|
reqwest({
|
||||||
url: 'features/' + changeRequest.name,
|
url: 'features/' + changeRequest.name,
|
||||||
@ -213,7 +239,9 @@ var Unleash = React.createClass({
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
data: JSON.stringify(changeRequest)
|
data: JSON.stringify(changeRequest)
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
}, this.handleError);
|
// all good
|
||||||
|
this.state.timer.start();
|
||||||
|
}.bind(this), this.handleError);
|
||||||
},
|
},
|
||||||
|
|
||||||
createFeature: function (feature) {
|
createFeature: function (feature) {
|
||||||
|
Loading…
Reference in New Issue
Block a user