Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 542
Pablo Jomer Avatar asked Aug 05 '26 00:08

Pablo Jomer


1 Answers

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)

like image 90
Caleb Avatar answered Aug 06 '26 15:08

Caleb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!