rx-splice

1.6.1 • Public • Published

RxJS splice operator

This package offers the RxJS splice operator: an eager variant of the groupBy operator.

Usage:

import { splice } from "rx-splice";
 
const input$ = Observable.from("a-value", "b-value", "c-value", /* more... */);
 
const spliced = splice(input$, (value: string) => value[0]);
 
spliced("a").subscribe(console.log);
spliced("b").subscribe(console.log);
// etc

Rationale

Using only idiomatic RxJS code, one would use filter instead for the use case of splice. However, if you are writing high performance code and this input$ Observable above (or more likely, Subject) would be subscribed hunderths or thousands of times (X), and thus the selector function of filter(fn) would be called X times. This can - and actually did prove to - be the biggest performance bottleneck in our application, so we wrote splice, which executes it's indexing selector only once for each emitted value.

Note that splice operates like share in how it subscribes upstream:

  • subscribing the first 'shard' will active the upstream subscription,
  • later subscriptions wont trigger additional upstream subscriptions and
  • unsubscribing the last subscription will unsubscribe the upstream subscription too.

Package Sidebar

Install

npm i rx-splice

Weekly Downloads

8

Version

1.6.1

License

MIT

Unpacked Size

5.33 kB

Total Files

5

Last publish

Collaborators

  • hermanbanken