Closed ghost closed 8 years ago
I don't know how you are making the request, but, this is how I do it:
class UsersActions {
/// ...
remove(id) {
axios.post("/users/remove", { id: id }).then((response) => {
this.actions.removeSuccess(response.data.id);
}, (error) => {
this.actions.removeFailed(error);
});
this.dispatch();
}
/// ...
}
/// ...
class RulesStore {
/// ...
constructor() {
this.users = {};
}
/// ...
handleRemoveSuccess(rules) {
if (id in this.users) {
delete this.users[id];
}
}
/// ...
}
I use the id in the response in this example, but jusr forwarding the (parameter) id from the remove function works fine too since the scope is saved.
I am fairly new to alt.js and have a question regarding updating the state in the success handler.
Let's say I have a UserStore and want to delete one User. I fire the delete user action with the
id
of the user which is ought to be deleted. The source sends a delete request with thatid
to the backend. The request works and the sources fire the success action.How do I remove the User from the StoreState in the success action handler, since I don't get the
id
or any other information about the made request passed?