A demo application showing a sample implementation of the BLoC pattern in React.
yarnyarn startA 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
StreamBuilderandAsyncSnapshotare 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
Sinkis 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 howMobXspecifically tags methods that mutate the state asactions. 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!