Handling Redux Side Effects with redux-observable

To handle Redux side effects, I (and others) prefer to writing sagas with redux-saga .

After @duivvv mentioned it to me on Twitter redux-observable also caught my eye. At the core site RxJS 5 and the concept of Epics which take a stream of actions and return a stream of actions. The library is used extensively over at Netflix where it was created by Jay Phelps and (now Googler) Ben Lesh.

Here’s an example Epic which listens for a SEARCH action, and then actually performs the actual search (until it is cancelled):

const searchEpic = (action$, store) =>
    .map(action => action.payload)
    .switchMap(query => 
      ajax.post('http://localhost:8080/search', {query})
    .map(res => ({type: 'SEARCH_DATA', result: res.response}))

💁‍♂️ If you’re entirely not familiar with RxJS then watch this ”RxJS Observables Crash Course” video

Next to some proper documentation there’s also a good introductory video available:

Understanding RxJS and Redux-Observable →

Related: Using RxJS and CSS Variables it’s very easy to create “Reactive Animations”

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.