Flux Dispatcher的目的是什么(与简单的实例方法相比)

时间:2017-01-18 16:56:18

标签: reactjs flux

我正在努力了解助焊剂调度员的目的。

这是一个简单的例子(取自http://blog.andrewray.me/flux-for-stupid-people/

// Single object representing list data and logic
var ListStore = {

    // Actual collection of model data
    items: []

};

// Tell the dispatcher we want to listen for *any*
// dispatched events

MicroEvent.mixin( ListStore );

AppDispatcher.register( function( payload ) {

    switch( payload.actionName ) {

        // Do we know how to handle this action?
        case 'new-item':

            // We get to mutate data!
            ListStore.items.push( payload.newItem );
            // Tell the world we changed!
            ListStore.trigger( 'change' );
            break;

    }

}); 

ListActions = {

    add: function( item ) {
        AppDispatcher.dispatch({
            eventName: 'new-item',
            newItem: item
        });
    }

};

```

在一天结束时我会简单地说

ListActions.add(12)

那么有一个调度员,然后创建add动作创建者服务(除了磨损我的键盘?)

即使在一个大型项目中,我也不确定这种模式在哪里做什么,但让我输入更多。

1 个答案:

答案 0 :(得分:0)