1.0.0 • Published 2 years ago

@rxjsx/rxjsx v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

RxJS Extensions

codeql Tests Status Coverage Status npm (scoped) Snyk Vulnerabilities for npm scoped package Run on Repl.it

RxJS operators to deal with arrays, tuples, and dragging the original values along while adding more values to the pipeline.

:hammer_and_wrench: Install

npm install --save @rxjsx/rxjsx rxjs

:technologist: Demo

import { of } from 'rxjs';
import { flatListMap } from '@rxjsx/rxjsx';

of([1, 2, 3], [4], [5, 6])
    .pipe(flatListMap(x => of(x, 10+x)))
    .subscribe(console.log);

You can experiment with the above code by forking this ReplIt repo or through this Medium article.

:open_book: Examples

// instead of this
of([1, 2, 3]).pipe(map(l => l.map(e => e * 2))

// you can do this
of([1, 2, 3]).pipe(listMap(e => e * 2)) // [2, 4, 6]
// instead of this
let device;
deviceService.getDevice(id)
  .pipe(tap(_device => device = _device))
  .pipe(flatMap(_device => userService.getUser(device.owner)))
  .pipe(map(_user => userService.unassignDevice(_user, _device)))

// you can do this
deviceService.getDevice(id)
  .pipe(flatZipMap(device => userService.getUser(device.owner)))
  .pipe(map(([device, user]) => userService.unassignDevice(user, device)))

:notebook: Manual

The available operators so far are the following:

OperatorDescription
flatMap / mergeMapRxJS's mergeMap alias
zipMapTo zip the transformed value with the original value
flatZipMap / mergeZipMapSimilar to zipMap, but to be used when a transformation returns an observable
projectToFormerTo project an observable of pairs, to get the first coordinate
projectToLatterTo project an observable of pairs, to get the second coordinate
projectToTo project an observable of tuples
mapFormerTo transform the first coordinate of an observable of pairs
mapLatterTo transform the second coordinate of an observable of pairs
flatMapFormer / mergeMapFormerSimilar to mapFormer, but to work on stream-returning transformations
flatMapLatter / mergeMapLatterSimilar to mapLatter, but to work on stream-returning transformations
listMapTo transform an observable of list, with a mapping on the list elements
flatListMap / mergeListMapTo transform an observable of list, with a stream-returning member transformation
listFlatMapTo transform an observable of list, with a list-returning member transformation
flatListFlatMap / mergeListFlatMapTo transform an observable of list, with a list-observable-returning transformation

:muscle: Thanks to all Contributors

List of Contributors

:books: Related Literature

:keyboard: Contributing

:pray: Support

This project needs your support. Don't forget to leave a :star: behind.