Reactive Programming in Frontend: EventEmitter, Redux, and Mobx
The article contrasts push‑based reactive programming with imperative code, then walks through a simple EventEmitter with manual cleanup, examines Redux’s store subscriptions and middleware overhead, explores Mobx’s automatic dependency tracking via getters, setters and autorun, and compares the boilerplate, performance, and hidden‑dependency trade‑offs before previewing a future post on using Observables for asynchronous events.
The article begins by contrasting reactive (push‑based) programming with traditional imperative (pull‑based) code, using everyday examples such as responding to a question.
It then presents a simple EventEmitter implementation, showing how button clicks can be handled with a push model and noting the need for manual cleanup in componentWillUnmount to avoid memory leaks.
Next, the author examines Redux’s approach: subscribing to the store, using mapState/dirty checking to detect changes, and employing middleware to react to specific actions, while pointing out efficiency concerns with large state and the implicit subscription of all actions.
The discussion moves to Mobx, illustrating how getters, setters, and computed properties enable automatic dependency tracking, and how autorun can handle asynchronous side effects, though it may collect unintended dependencies requiring extra disposer code.
Finally, the piece highlights the trade‑offs of each technique—EventEmitter’s boilerplate, Redux’s middleware overhead, and Mobx’s hidden dependencies—and teases a forthcoming blog on using Observables for asynchronous event handling.
Youzan Coder
Official Youzan tech channel, delivering technical insights and occasional daily updates from the Youzan tech team.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.