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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rxjs-redux

v1.1.4

Published

React-Redux-like bindings for Redux Observable

Downloads

197

Readme

RxJS-Redux

Simple, yet powerful, epics built on top of Redux-Observable.

What is this?

This library builds on top of redux-observable to help you implement epics that are easy to understand and testable.

Our experience shows that RxJS by itself can be hard to learn, understand and manage. RxJS-Redux provides with a simple and consistent pattern for building epics that leverage the power of RxJS while keeping the epics simple.

How it works

RxJS-Redux is for RxJS and Redux, what react-redux is for React and Redux. So much so, that it can be explained with a rehashed description of react-redux:

rxjs-redux is conceptually pretty simple. It subscribes to the stream of Redux state, checks to see if the data your epic wants has changed, and re-executes the business logic of your epic.

If you're using react-redux for your UI, using rxjs-redux for Epics should be a no-brainer, thanks to the familiar approach.

Install

This has peer dependencies of [email protected], [email protected] and [email protected], which will have to be installed as well.

   npm install --save rxjs-redux

or

   yarn add rxjs-redux

Usage

This library integrates out of the box with redux-observable.

import { connect, stateObserverAsEpic } from 'rxjs-redux';
import { combineEpics } from 'redux-observable';

const mapStateToProps = (state: State) => ({
  property: state.property
});

const mapPropsToAction = (props: Props) => {
    if (property === "SPECIAL") {
      return { type: "SPECIAL_DETECTED" };
    }
    return { type: "BORING_PROPERTY", property };
}

const stateObserver = state$ => state$.pipe(
    connect(mapStateToProps),
    map(mapPropsToAction)
);

combineEpics(
  stateObserverAsEpic(stateObserver)
);

Custom props equality

const arePropsEqual = (previousProps: Props, currentProps: Props) => {
  return previousProps.singleProperty === currentProps.singleProperty;
};

state$.pipe(
    connect(mapStateToProps, { arePropsEqual }),
    map(mapPropsToAction)
);

Recipes

Dispatch plain actions

const mapPropsToActions = (props: Props) => {
    return [...];
}

state$.pipe(
    connect(mapStateToProps),
    map(mapPropsToActions),
    flatMap(actions => from(actions))
);

Dispatch actions from an asynchronous operation

Use when you need to invoke an asynchronous operation that returns an action - most commonly when calling REST API.

const mapPropsToObservable = (props: Props) => {
    return from(returnPromise(props));
}

state$.pipe(
    connect(mapStateToProps),
    flatMap(mapPropsToObservable)
);

Separate "context" - that is required downstream, but shouldn't retrigger the epic

const mapPropsToObservable = (props: Props) => {
    return from(returnPromise(props.contextState));
}

const mapStateToStateProps = (state: State) => ({
  property: state.property
});

const mapStateToContextProps = (state: State) => ({
  contextState: state.contextState
});

// mapPropsToObservable will only be executed when "property" changes
// and the latest value of contextState will be included in Props
state$.pipe(
    connect(mapStateToStateProps, mapStateToContextProps),
    flatMap(mapPropsToObservable)
);

Limit invocations to one at a time

Sometimes props change faster than the time required to finish async operation. If that happens, it helps to:

  • run only one mapPropsToObservable at a time (ignoring other prop changes in the meantime)
  • always make sure mapPropsToObservable one final time with the most recent props.

You can get this behaviour by replacing flatMap operator with auditMap:

import { auditMap } from 'rxjs-redux';

const mapPropsToObservable = (props: Props) => {
    return from(returnPromise(props));
}

state$.pipe(
    connect(mapStateToProps),
    auditMap(mapPropsToObservable)
);

Trigger side effect

Use when your epic is causing a side effect - eg. setting a cookie or calling a REST API where you don't care about response.

const mapPropsToSideEffect = (obs: Observable<Props>) =>
    obs.pipe(
        tap(props => { ... }),
        ignoreElements()
    );

state$.pipe(
    connect(mapStateToProps),
    mapPropsToSideEffect
);

Handle changes in collections

// Item Epic

const mapItemToProps = (props: ItemProps) => ({
  id: props.item.id,
  description: props.item.description,
  context: pops.context
});

const processItem = (inputProps$: Observable<ItemProps>) =>
  itemProps$.pipe(
    connect(mapItemPropsToProps),
    flatMap(props => {
      return { type: "CHANGED_IN_ITEM", id: item.id, id: item.description, context };
    })
  );

// List Epic

const mapInputToProps = (state: State) => ({
  list: state.list,
  context: state.context
});

const arePropsEqual = (previousProps: Props, currentProps: Props) => {
  return previousProps.list === currentProps.list;
};

state$.pipe(
    connect(mapInputToProps),
    flatMap(props => {
      return from(props.list).map(item => ({
        item,
        context: props.context
      }))
    }),
    groupBy(item => item.id),
    flatMap(processItem)
);

Testing

Testing RXJS code can be often quite cumbersome. In most cases this library helps you keep your logic outside of RxJS and test it independently.

When you follow pattern explained by recipes, you can focus your testing on these methods:

  • mapInputToProps
  • arePropsEqual
  • mapPropsToActions, mapPropsToObservable, etc.

License

Blue Oak Model License

MIT (src/shallowEqual.ts)