Skip to content

typeheim/rx-flow

Repository files navigation

RxFlow

Collection of reactive libraries to ease your life

NPM Version Build Status Package License Discord

FireRx

FireRx extends RxJS with different useful features. Adds memory safety and garbage collection features to work with subjects and subscriptions, subjects that behave both like subjects and promises to support async/await and many more.

Getting Started

Install package

yarn add @typeheim/fire-rx
//or
npm -i @typeheim/fire-rx

Custom Obsevrables

FireRx adds custom observable types, like StatefulSubject that acts as ReplaySubject and Promise so that you can use async/await operators on it as well as regular Subject methods. Adds memory safety and garbage collection automatically calling unsubscribe on subscriptions.

import { StatefulSubject } from '@typeheim/fire-rx'

let subject = new StatefulSubject<number>()

subject.next(5)  
await subject // returns 5

subject.next(6)
await subject // returns 6

subject.stop() // completes subject and unsubscribe all subscriptions

FireRx provide set of features for garbage collection, like StopOnDestroy decorator for FireRx custom observables that extends Angular destructor(ngOnDestroy) or custom destructor (specified at decorator metadata) and stop specified observable.

class WithoutDestructor {
    @StopOnDestroy()
    valueSubject = new ValueSubject(1)

    @StopOnDestroy()
    statefulSubject = new StatefulSubject()
}

Read more about FireRx...