P
P
Peter2015-07-28 15:50:56
React
Peter, 2015-07-28 15:50:56

How to overcome synchronous requests in the Flux dispatcher?

The flux architecture uses a dispatcher that can only work synchronously. Therefore, in large applications, it happens that actions occur in the dispatcher and cause an error.
Of course, you can make several dispatchers, but something tells me that this is not the best option, although maybe I didn’t understand it properly.
Therefore, the question is:
How to make the Flux architecture correctly, so that actions do not occur in the dispatcher, for a large single-page application?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Goryachkin, 2015-07-28
@abaddon65

It's really strange how they can intersect. Well, okay, take the documentation, everything is written there quite well, the meaning is this, you have a Dispatcher.
Create class App.Dispatcher.js (everything will be in ES6):

import {Dispatcher} from 'flux';
export default new Dispatcher();

You have an AppActions action, it has something like this:
import AppDispatcher from './AppDispatcher.js';
export default {
    firstAction(){
        AppDispatcher.dispatch({
            actionType: 'FIRST__ACTION'
        });
    },
    secondAction(){
        AppDispatcher.dispatch({
            actionType: 'SECOND__ACTION'
        });
    }
}

Well, of course, the AppStore storage:
import AppDispatcher from './AppDispatcher.js';
export default class AppStore {
    constructor() {
         AppDispatcher.register(function (action) {
             switch (action.actionType) {
                 case 'FIRST__ACTION':
                     //Первое действие
                     break;
                 case 'SECOND__ACTION':
                     //Второе действие
                     break;
             }
         });
    }
}

Yes, that’s actually all, there’s nothing that you won’t intersect here. Well, the norms tutorial is here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question