B
B
bio2016-08-19 09:03:59
Angular
bio, 2016-08-19 09:03:59

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
            });
        })
    }

}

2. I correctly understand that one store for one data type?
For example, if we have a page with a list of tasks and a task page, then we get two store ?
If so, then the list of tasks cannot be saved by itself, this will happen through the task store. In turn, the task store will communicate with the list of tasks and update the data there ... I think something is
wrong here :( and if you need to track a specific action?
For example: there is a select with a list, next to the "add" button. When you click on add, the add form opens. After successful addition, a new item should be added to the list and immediately selected. How to implement this knowing only that that somethingchanged, because anything can change.
07a4ebc573.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question