var Header = React.createClass({ /** * @return {object} */ render: function() { return ( <header id="header"> <h1>todos</h1> <TodoTextInput id="new-todo" placeholder="What needs to be done?" onSave={this._onSave} /> </header> ); }, /** * Event handler called within TodoTextInput. * Defining this here allows TodoTextInput to be used in multiple places * in different ways. * @param {string} text */ _onSave: function(text) { if (text.trim()){ TodoActions.create(text); } } });
var Dispatcher = require('flux').Dispatcher; var assign = require('object-assign');
var AppDispatcher = assign(new Dispatcher(), { /** * @param {object} action The details of the action, including the action's * type and additional data coming from the server. */ handleServerAction: function (action) { this.dispatch({ source: 'SERVER_ACTION', action: action }); },
/** * A bridge function between the views and the dispatcher, marking the action * as a view action. Another variant here could be handleServerAction. * @param {object} action The data coming from the view. */ handleViewAction: function(action) { this.dispatch({ source: 'VIEW_ACTION', action: action }); } });
module.exports = AppDispatcher;
stores
感觉和一般 MVC 里面的 model 比较类似,官网说:
Their role is somewhat similar to a model in a traditional MVC, but they manage the state of many objects — they are not instances of one object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
var TodoStore = assign({}, EventEmitter.prototype, {