Preact: Is there any EventEmitter implementation for Preact?

Created on 3 Oct 2016  路  6Comments  路  Source: preactjs/preact

I want to use preact with websockets. But I wonder is it possible using with EventEmitter likes facebook's one.

question

Most helpful comment

Thanks! Well, the original EventEmitter from Node can already be used in the browser. It just pulled in some dependencies that I didn't want. When using React you hardly notice it, but with Preact you see how your bundle more than doubles in size when you pull in EventEmitter from Node because Preact is so tiny! :) So it seemed too much of a waste to do that...

It turns out that more modules pull in more than we bargained for... I also ended up creating my own version of debug, named ulog and I also forked Kriasoft's Universal Router and named it uroute. The reason I don't use preact-router is because I am doing server-side rendering and want to start rendering the page before the data has come back from e.g the database. So I need a router where I can easily decouple routing from rendering. But Universal Router (while a brilliant piece of code) uses Generators, which requires the Babel generator runtime, which is too big for my liking. So... :)

All 6 comments

@mehmetkose you can just use the same EventEmitter (the Facebook one). Shouldn't be any different in preact. We have a 200 byte functional version of EventEmitter we'll likely release soon, but for now Facebook's seems reasonable.

(Closing since I think that answers your question, but let me know if I missed the point!)

@developit no question. thank you.

I built a port of Node's EventEmitter that is smaller, more functional and independent from other Node libs. I am using it with Preact. It can be found here:

uevents

It's pre-1.0.0 so any feedback is welcome!

We have a 200 byte functional version of EventEmitter we'll likely release soon

Sounds interesting! Maybe we could combine our efforts? My current implementation is a full port, but this could probably be trimmed down.

Wow that looks like an amazing drop-in for events - have you thought about submitting it as an official "browser" alias for the node module? Nice work!

Thanks! Well, the original EventEmitter from Node can already be used in the browser. It just pulled in some dependencies that I didn't want. When using React you hardly notice it, but with Preact you see how your bundle more than doubles in size when you pull in EventEmitter from Node because Preact is so tiny! :) So it seemed too much of a waste to do that...

It turns out that more modules pull in more than we bargained for... I also ended up creating my own version of debug, named ulog and I also forked Kriasoft's Universal Router and named it uroute. The reason I don't use preact-router is because I am doing server-side rendering and want to start rendering the page before the data has come back from e.g the database. So I need a router where I can easily decouple routing from rendering. But Universal Router (while a brilliant piece of code) uses Generators, which requires the Babel generator runtime, which is too big for my liking. So... :)

That's awesome. I wonder if we can find a way to transpile generators to something smaller?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jescalan picture jescalan  路  3Comments

matthewmueller picture matthewmueller  路  3Comments

philipwalton picture philipwalton  路  3Comments

skaraman picture skaraman  路  3Comments

SabirAmeen picture SabirAmeen  路  3Comments