saferx
TypeScript icon, indicating that this package has built-in type declarations

0.4.2 • Public • Published

SafeRx

npm version

"Safe" extensions and utilities for the RxJS:

Installation

Installing all libraries:

npm i saferx

Installing the certain library:

npm i @saferx/<LIBRARY_NAME>

Usage

Full demo available in packages/saferx/demo

import { CallableSubject, safeSwitchMap, withInProgress, selectError, selectInProgress, selectValue } from "saferx";
import { shareReplay } from "rxjs/operators";

import { api, API } from "./api";

export class UserService {
    loadUser = new CallableSubject<{ id: number }>();

    private user = this.loadUser.pipe(
        safeSwitchMap(({ id }) => this.api.loadUser(id)),
        withInProgress,
        shareReplay(1)
    );

    user$ = this.user.pipe(selectValue);
    userError$ = this.user.pipe(selectError);
    userInProgress$ = this.user.pipe(selectInProgress);

    constructor(private api: API) {}
}

const user = new UserService(api);
user.user$.subscribe(console.log);
user.loadUser({ id: 1 });

Examples with specific libraries are available in the "ReadMe" of these packages

Contributing

Initialize

yarn bootstrap

Publish

yarn release

Readme

Keywords

Package Sidebar

Install

npm i saferx

Weekly Downloads

0

Version

0.4.2

License

MIT

Unpacked Size

6.94 kB

Total Files

9

Last publish

Collaborators

  • krickray