五、Action
每个Action都是一个对象,包含一个actionType
属性(说明动作的类型)和一些其他属性(用来传递数据)。
在这个Demo里面,ButtonActions
对象用于存放所有的Action。
// actions/ButtonActions.js var AppDispatcher = require("../dispatcher/AppDispatcher"); var ButtonActions = { addNewItem: function (text) { AppDispatcher.dispatch({ actionType: "ADD_NEW_ITEM", text: text }); }, };
上面代码中,ButtonActions.addNewItem
方法使用AppDispatcher
,把动作ADD_NEW_ITEM
派发到Store。