npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rxjs-multiscan-operator

v1.1.0

Published

RxJS operator for sharing state between Observables

Readme

Observable.multiScan

Custom RxJS 5 operator for sharing state between Observables in safe and controlled manner. It is an extension of scan operator for multiple Observables.

Motivation

Say you are displaying two buttons and a counter (starting with zero) on a web page. When user clicks first button, the counter should be increased by one. When second button is clicked, counter should be decreased.

Usual solution is to merge two Observables, somehow mark values from each and then use scan detecting with switch statement if we should increase or decrease counter. This results in Redux-like code:

const allClicks = Observable.merge(
    clicksFromFirst.mapTo({type: 'INCREASE'}), 
    clicksFromSecond.mapTo({type: 'DECREASE'})
);

const counterValues = allClicks.scan((counter, click) => {
    switch (click.type) {
        case 'INCREASE':
            return counter + 1;
        case 'DECRASE':
            return counter - 1;
        default:
            throw Error(`Unknown click type: ${click.type}`)
    }
}, 0);

Redux is cool architecture, but this is a bit much to simply share some stateful computation between Observables. There is quite a lot of boilerplate. Default case is handled awkwardly and we even know that it will never happen, but the linter will still complain. Also TypeScript handles such code poorly, since it is difficult for compiler (without additional help and thus more boilerplate) to guess what values will appear in reducer function.

With multiScan the same functionality can be implemented like so:

const counterValues = Observable.multiScan(
    [clicksFromFirst, (counter, click) => counter + 1],
    [clicksFromSecond, (counter, click) => counter - 1],
    0
);

We are passing arrays, which have two elements each: Observable with some values and a reducer function. We also pass initial value, just as in regular scan.

Whenever any of passed Observables emits a value, corresponding reducer will be used to update state. When the other Observable emits, its reducer will be called with the previously updated state.

Now Observables share state in safe and predictable manner.

Usage

Since multiScan operator is not a Observable method, but static function, you can simply import and use it directly:

import { multiScan } from 'rxjs-multiscan-operator';

If you want your multiScan always close, there is an option to patch Observable object as well. Just don't blame me for any name conflicts!

import 'rxjs-multiscan-operator/add';