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

0.0.2 • Public • Published

Rx-if

Installation

npm install rx-if

Usage

interval(1000).pipe(
  map(n => n + 1),
  rxIf(n => n % 3 === 0).pipe(
    mapTo('Fizz'),
  ),
  take(7),
).subscribe(console.log);
// output: 1, 2, Fizz, 4, 5, Fizz, 7
interval(1000).pipe(
  rxIf(n => n % 2 === 0).pipe(
    map(n => n / 2),
  ).else(
    map(n => n * 2)
  ),
  take(10),
).subscribe(console.log);
// output: 0, 2, 1, 6, 2, 10, 3, 14, 4, 18
const messages$ = userService.currentUser().pipe(
  rxIf(user => user === null).pipe(
    switchMap(() => userService.createUser()),
    switchMap(user => messagesService.createWelcomeMessage(user)),
  ).else(
    switchMap(user => messagesService.getMessages(user)),
  ),
  map(messages => orderByDate(messages)),
  rxIf(messages => messages.length > 5).pipe(
    map(messages => messages.slice(-5)),
  )
);

Readme

Keywords

Package Sidebar

Install

npm i rx-if

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

10.4 kB

Total Files

5

Last publish

Collaborators

  • shalom_pele