A demo application showing a sample implementation of the BLoC pattern in React.
yarn
yarn start
A Counter component's state is implemented in 4 different ways:
- Using the State object
- Using MobX
- Using Subject from RxJS
- Using the BLoC pattern
This demo is intended to show how the BLoC pattern (a pattern specifically for Flutter) differs from other methods. The syntax of Dart can be a bit hard to understand due to the syntax noise (as compared to JSX), so implementing it in React might allow for a different perspective in understanding the BLoC pattern.
- The implementation of
StreamBuilder
andAsyncSnapshot
are just approximations and have only been partially implemented just to satisfy the needed features for the demo. - Most of the BLoC demos out there show that the
Sink
is exposed as public. I'm not entirely sold on the idea of exposing it; I thinkadd()
(next()
in RxJS) should be called as an action, similar to howMobX
specifically tags methods that mutate the state asaction
s. This ensures that the operations being done on the stream are encapsulated and are explicitly labeled (ie.increment()
,decrement()
) - Inspiration: Brian Egan - Build a Reactive Flutter App!