Search code examples
javascriptnode.jsgoreactjsflux

Building Flux/React application without NodeJs EventEmitter


Hi I'm trying to build a Flux/React application with a go-lang back-end. I have been following a tutorial I found here. But I have a problem when building the store. In the tutorial something like this is used to create a base for the store.

var ProductStore = _.extend({}, EventEmitter.prototype, {...});

The problem I have is I do not have access to the EventEmitter library which I understand is a Nodejs lib? Is there an alternative I can use?


Solution

  • You can use NodeJS libraries in the browser! Take a look at browserify.

    First some code:

    // index.js
    var EventEmitter = require("events").EventEmitter;
    var ProductStore = function() {};
    ProductStore.prototype = new EventEmitter;
    

    Then you run browserify on it:

    browserify index.js > bundle.js
    

    Also worth a look is WebPack which does the same thing. (but has some additional features)