I mentioned this problem in issue #14 but couldn't figure out the fix yet. So here is my example code:
example.js
"use strict";
var React = require("react"),
ReactFlux = require("react-flux");
var constants = ReactFlux.createConstants([
"FETCH",
], "RESOURCE");
var actions = ReactFlux.createActions({
fetch: [constants.FETCH, function (params) {
return $.ajax({
url: "/error_call",
error: function () {
console.log("error callback for $.ajax"); // This gets called every time.
}
});
}]
});
var store = ReactFlux.createStore({
getInitialState: function () {
return {
isLoading: false
};
}
}, [
[constants.FETCH, function onFetch () {
console.log("onFetch"); // This gets called every time.
this.setState({
isLoading: true
});
}],
[constants.FETCH_ERROR, function onFetchError () {
console.log("onFetch Error"); // This gets called only on first fail.
}],
[constants.FETCH_AFTER, function onFetchAfter () {
console.log("onFetch After"); // This gets called only on first fail.
this.setState({
isLoading: false
});
}]
]);
var Component = React.createClass({
mixins: [ store.mixin() ],
getStateFromStores: function () {
return {
request: store.state
};
},
render: function () {
return (
<button onClick={this._onClickButton} disabled={this.state.request.get("isLoading")}>Send Request</button>
);
},
_onClickButton: function () {
actions.fetch();
}
});
React.render(<Component />, document.body);
Let's say I have a API route which returns error for some reason (404, 403, 500, whatever). In that case after the first call when the request fails Flux store listener calls onFetchError and onFetchAfter callbacks but when I try to click the button (send request) again without refreshing the page the request is being sent (callback onFetch called) but then none of the onFetchError and onFetchAfter is being called when another error occurs. The $.ajax error callback is called every time. Looks like on the first try the error exception is beiing muted and on next calls the state for that is not cleared.
I mentioned this problem in issue #14 but couldn't figure out the fix yet. So here is my example code:
example.js
Let's say I have a API route which returns error for some reason (404, 403, 500, whatever). In that case after the first call when the request fails Flux store listener calls
onFetchErrorandonFetchAftercallbacks but when I try to click the button (send request) again without refreshing the page the request is being sent (callbackonFetchcalled) but then none of theonFetchErrorandonFetchAfteris being called when another error occurs. The$.ajaxerror callback is called every time. Looks like on the first try the error exception is beiing muted and on next calls the state for that is not cleared.