0.4.2 • Published 3 years ago

saferx v0.4.2

Weekly downloads
10
License
MIT
Repository
github
Last release
3 years ago

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
0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

4 years ago

0.1.0

4 years ago