Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-observable

Package Overview
Dependencies
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-observable

RxJS based middleware for Redux. Compose and cancel async actions and more.

  • 0.16.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
246K
increased by0.3%
Maintainers
4
Weekly downloads
 
Created

What is redux-observable?

redux-observable is a middleware for Redux that allows you to handle asynchronous actions using RxJS observables. It enables complex async flows in your Redux applications by leveraging the power of reactive programming.

What are redux-observable's main functionalities?

Handling Asynchronous Actions

This feature allows you to handle asynchronous actions such as API calls. The example demonstrates an epic that listens for 'FETCH_USER' actions, makes an AJAX request to fetch user data, and dispatches either a 'FETCH_USER_FULFILLED' or 'FETCH_USER_FAILED' action based on the result.

const fetchUserEpic = action$ => action$.pipe(
  ofType('FETCH_USER'),
  mergeMap(action =>
    ajax.getJSON(`/api/users/${action.payload}`).pipe(
      map(response => ({ type: 'FETCH_USER_FULFILLED', payload: response })),
      catchError(error => of({ type: 'FETCH_USER_FAILED', payload: error }))
    )
  )
);

Combining Multiple Epics

redux-observable allows you to combine multiple epics into a single root epic. This is useful for organizing your code and managing complex async flows. The example shows how to combine `fetchUserEpic` with another epic.

const rootEpic = combineEpics(
  fetchUserEpic,
  anotherEpic
);

Cancellation of Actions

redux-observable supports the cancellation of ongoing actions. The example demonstrates using `switchMap` to cancel any ongoing AJAX request if a new 'FETCH_USER' action is dispatched, ensuring only the latest request is processed.

const fetchUserEpic = action$ => action$.pipe(
  ofType('FETCH_USER'),
  switchMap(action =>
    ajax.getJSON(`/api/users/${action.payload}`).pipe(
      map(response => ({ type: 'FETCH_USER_FULFILLED', payload: response })),
      catchError(error => of({ type: 'FETCH_USER_FAILED', payload: error }))
    )
  )
);

Other packages similar to redux-observable

Keywords

FAQs

Package last updated on 16 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc