Hacker News new | ask | show | jobs
by acdlite 4148 days ago
Agree that singletons for Flux are bad, but they're totally not necessary (e.g. https://github.com/acdlite/flummox). And if you don't like Flux, don't use it. I don't see how that's can be a demerit against React, since they're completely separate things.
1 comments

React doesn't have a good pattern for passing information up the tree other than Flux. Prior to Flux they told everyone to pass functions through props which is fine up until a certain point but it doesn't scale to large apps. Flux does solve it, and is a generally good idea, but the singleton pattern breaks when applied to the server.
Ah, I see. I don't really agree, because I think the enforced unidirectional data flow is one of the best parts of React, but that's certainly a valid point of view.

I just want to emphasize again that Flux is entirely possible without singletons, and works just as well on the server if you create new instances for every request. Flummox does it, Fluxible does it (at least for stores). It's just a shame Facebook pushed singletons and then everyone followed their lead.

Honestly I think FB put the flux pattern out before that idea had become fully developed looking for feedback from the community. The flux repo explicitly states that none of the examples are used by facebook or even resemble facebook (client-side) code. The dispatcher, which was released months after they announced flux, is the only component in the flux they admit to using. Immediately after it's release (even before the dispatcher) we began writing client-side javascript code based on arbitrary examples meant to demonstrate a concept.

I also think flux's real-world implementation came from the necessity to build React components within pre-built apps, where they simply didn't have the ability to pass down props because they had to create complete separate components.

passing functions through props scales up to large apps fantastically better than any other not-React based approach I've ever used. I've done it.