saferx
v0.4.2
Published
Safe extensions and utilities for the RxJS
Downloads
1
Readme
SafeRx
"Safe" extensions and utilities for the RxJS:
- Callable Subject - subjects that can be called
- Multi Observable - wrapper for several observables at once
- Safe operators - materialize start and end of operator
- Observe - observe class property to subject
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
- Package manager: Yarn
- Monorepo: Lerna
- Commits: Conventional commits
- Code formatter: Prettier
Initialize
yarn bootstrap
Publish
yarn release