1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

only optimistic update if success

This commit is contained in:
ivaosthu 2014-11-01 12:03:50 +01:00 committed by Ivar Conradi Østhus
parent b2d4cbf5de
commit c6118baad3

View File

@ -64,21 +64,24 @@ var Unleash = React.createClass({
}, },
createFeature: function (feature) { createFeature: function (feature) {
var unsaved = [], state = this.state; var created = function() {
var unsaved = [], state = this.state;
this.state.unsavedFeatures.forEach(function(f) { this.state.unsavedFeatures.forEach(function(f) {
// TODO: make sure we don't overwrite an existing feature // TODO: make sure we don't overwrite an existing feature
if (f.name === feature.name) { if (f.name === feature.name) {
state.savedFeatures.unshift(f); state.savedFeatures.unshift(f);
} else { } else {
unsaved.push(f); unsaved.push(f);
} }
}); });
this.setState({unsavedFeatures: unsaved});
}.bind(this);
this.setState({unsavedFeatures: unsaved});
this.state.featureStore.createFeature(feature) this.state.featureStore.createFeature(feature)
.then(function(r) { console.log(r.statusText); }.bind(this)) .then(created)
.catch(this.handleError); .catch(this.handleError);
}, },