Skip to content

Latest commit

 

History

History
83 lines (68 loc) · 5.13 KB

README.md

File metadata and controls

83 lines (68 loc) · 5.13 KB

RxJS Extensions

codeql Tests Status Coverage Status npm (scoped) Snyk Vulnerabilities for npm scoped package @rxjsx/rxjsx Maintainability

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

🛠️ Install

npm install --save @rxjsx/rxjsx rxjs

🧑‍💻 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.

📖 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)))

📓 Manual

The available operators so far are the following:

Operator Description
flatMap / mergeMap RxJS's mergeMap alias
zipMap To zip the transformed value with the original value
flatZipMap / mergeZipMap Similar to zipMap, but to be used when a transformation returns an observable
projectToFormer To project an observable of pairs, to get the first coordinate
projectToLatter To project an observable of pairs, to get the second coordinate
projectTo To project an observable of tuples
mapFormer To transform the first coordinate of an observable of pairs
mapLatter To transform the second coordinate of an observable of pairs
flatMapFormer / mergeMapFormer Similar to mapFormer, but to work on stream-returning transformations
flatMapLatter / mergeMapLatter Similar to mapLatter, but to work on stream-returning transformations
listMap To transform an observable of list, with a mapping on the list elements
flatListMap / mergeListMap To transform an observable of list, with a stream-returning member transformation
listFlatMap To transform an observable of list, with a list-returning member transformation
flatListFlatMap / mergeListFlatMap To transform an observable of list, with a list-observable-returning transformation

💪 Thanks to all Contributors

List of Contributors

📚 Related Literature

⌨️ Contributing

🙏 Support

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