More Utility Operators for RxJS
I love RxJS, but there are a few operators that I often reach for that aren't part of the core library. In other libraries, I'd be pestering the maintainers to add them, but this is RxJS! There's no need to change the library, when we can just create functions, and if they're just functions, they can be released in their own packages, á la Lodash!
This repo is my personal collection of utilities, so if it's in here, I've used it in some project at some time, whether I was doing that project for love or for money. Some of them are as simple as a chisel, and some of them are as dangerous as a table saw, and some as esoteric as a Japanese rasp saw. Some of them are very broad in their scope, and some are very specific to a framework, runtime, or coding purpose.
I hope they help you with your projects, or at least teach you something about how RxJS works. I know they've taught me.
- loop Like
repeat
, but you get know what repetition you're on. - loopScan Like loop, but you can pass state between repetitions.
- deferAbort Allows you to turn a function that uses the AbortController API into an Observable.
- deferOf -- Like
defer
, but it creates an Observable of just one value.
- safeMap Parse and validate incoming data in just one step. Pairs great with Zod.
- withAbort Allows you to trigger Observable cleanup with an AbortSignal.
- react-hooks A collection of React Hooks that help sync Observables with React component lifecycles
useSubscribe
- Syncs an RxJS Subscription lifetime to React lifecycles.useObserve
- Creates a stateful Observable that watches React states and props.useObserveChanges
- Creats an Observable of changes to React states and props.useSubject
- A Subject that is created on mount on completed on unmountuseBehaviorSubject
- A BehaviorSubject (i.e. a stateful Subject) that is created on mount and completed on unmount
Got a suggestion for a new feature, feedback on an existing one, or other ways to improve this codebase? Please feel free to add an issue!
Want to show your appreciation? Buy me a coffee!