Answer the question
In order to leave comments, you need to log in
How to organize work with Flux in Angular?
Hello! Help deal with flux.
1. Where to perform CRUD operations?
Now I do it in action, but on the Internet they write that it is impossible there.
It is not clear to me why there is no action, since communication with the "world" takes place here. Each action returns a Promise, for example for use in resolve in ui-router.
Code example:
class TodoAction {
constructor($http) {
this.$http = $http;
}
loadList(params) {
return this.$http.get('/todos', {
params: params
}).then((response) => {
AppDispatcher.dispatch({
actionType: TodoConstants.todo_LIST_LOAD,
todos: response.data.todos
});
return response.data.todos;
})
}
create (todo) {
return this.$http.post('/todo/save', {
todo_data: todo
}).then((response) => {
AppDispatcher.dispatch({
actionType: TodoConstants.todo_CREATE,
todo: response.data.todo
});
})
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question