Hacker News new | ask | show | jobs
by findjashua 3962 days ago
I like me some React, but my only gripe w it is the synthetic events, which can result in a single model's state being updated by multiple listeners.

I have replaced synthetic events w event streams, and couldn't be happier w how much cleaner the code has become as a result of replacing setters with stream-combinators.

The architecture roughly follows Elm's Model-View-Update, by splitting each component into view.jsx and update.js.

1. Update contains the eventstreams (replacement for synthetic events), and are transforms them into update-streams.

2. The model combines multiple update streams to return a model-stream.

3. The view combines multiple model streams, and the subscriber at the end does a `setState` to trigger the re-render

Using streams also has the side-benefit of not needing the didUpdate, shouldUpdate etc lifecycle hooks.

Here's a gist w the eventstream code: https://gist.github.com/findjashua/e78063e6591a2c234919

Happy to answer any questions.

Edit: special thx to Andre Staltz for the insightful discussions.