Rx-Helper
npm install -S rxjs rx-helper
What Is Rx-Helper?
Rx-Helper is a library to help you use the power of RxJS to:
- Modularize your apps, building out from a core of framework-independent logic
- Stub out unknowns so you can get right to work on the essence of your application
- Have a clean architecture that allows you to swap out UI frameworks, persistence tiers, or any other component while leaving most of your program unchanged.
What's the API?
There are only 4 important functions in the public API: The 2 that get events into an Agent, and the 2 that flexibly assign Handlers to a subset of those events.
- Through either
process
ortrigger
, an instance ofAgent
is given events— objects with atype
field (Flux Standard Actions). - If you have an Observable of items to process as events, you can pass it to
subscribe
. - Events are synchronously processed through Handler functions attached via
filter
- Async processing is begun by Handlers attached via
on
, whose concurrency mode (parallel
,serial
,cutoff
,mute
) can be specified to control what it does in the event of overlap with its own previous event processings.
Handler functions can be written to explicitly call trigger
or process
on the events they create. However, the config argument to on
allows them to declare that they will make their events available as an Observable, and set that Observable to be processed as events using either the processResults: true
, or type: String
parameter.
What Benefits Can I Get By Using It?
- A Clean Architecture of code with a high degree of decoupling and fault-tolerance.
- A clean, cancelable model of async effects, compatible with, but not dependent on a component library like React or Angular.
- Faster prototyping by building abstractions that simulate input or output, allowing you to focus on the core functionality of your app.
- Take advantage the Observable datatype - a type that is a superset of Promise, with a high degree of performance-tunability.
- Solve performance and timing issues declaratively, keeping code mostly free from those details by applying modes for these common use cases:
What kinds of apps can I build with it?
There are many demo apps included in this project that show what you can build.
- A Single Page App using React
- A Web Server using Express
- A utility that turns all-at-the-end AJAX requests for arrays (eg
/users/
) into streaming Observables - A Canvas-based requestAnimationFrame animation.
- A console app that writes names to a file, and speaks them aloud.
- A console app that detects a cheat-code of 5 clicks in a short interval.
- A Web Audio app that streams and queues up music from attachments in your Inbox.
- An IOT application interfacing with Raspberry Pi GPIO
OK, but where should I start?
The Wiki is a great place and has some case-studies.
If you're interested in learning more, or updating me on your progress, tweet me!
Testing? Yes, please!
Rx-Helper is highly tested. And since testing async is hard, some integration level tests run a bunch of complex stuff (our demos), and simply assert on the console output. The slightest change in behavior can thus be visible in the output of the demo as a large change. This, with Jest Snapshot testing makes asserting on our output a piece of cake.
Show your love!
- Display a badge on your project:
Gratitude, Props, Thanks To
- Dan Abramov - Redux
- Alex Jover Morales - Typescript Library Starter
- All who worked on RxJS, Redux Observable
References
- Martin Kleppmann - Turning the Database Inside Out
- Markus Eisele - Building Reactive Systems Using the Actor Model
- Martin Fowler - CQRS
- Bob Martin - Clean Architecture