Creating a dispatcher
Now let's implement this data flow. We'll start by creating a dispatcher first. Facebook offers us its implementation of a dispatcher that we can reuse. Let's take advantage of this.
Navigate to the
~/snapterestdirectory and run the following command:npm install --save fluxThe
fluxmodule comes with aDispatcherfunction that we'll be reusing.Next, create a new folder called
dispatcherin our project's~/snapterest/source/dispatcherdirectory. Now create theAppDispatcher.jsfile in it:var Dispatcher = require('flux').Dispatcher; module.exports = new Dispatcher();
First, we import Dispatcher provided by Facebook, then create, and export a new instance of it. Now we can use this instance in our application.
Next, we need a convenient way of creating and dispatching actions. For each action, let's create a function that creates and dispatches that action. These functions will be our action creators.