Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RxJS in Action: interacting with frameworks like React and Redux  RSS feed

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66047
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the "About" section for the book:
About this book wrote:interacting with frameworks like React and Redux.


As someone working in React and Redux (and rather liking it despite some typically cynical opinions), where exactly in the scheme of things does RxJs fit into the Redux world?
 
Pau Daniels
Author
Greenhorn
Posts: 8
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent kickoff question!

In the book we talk about the circle that is formed by React and Redux, where actions from React power state changes through reducers in Redux which in turn can power UI re-rendering and so on and so forth.

One awesome aspect about this kind of pattern is that there is a de-coupling between producing actions and processing actions. This makes an ideal entry point for Observables, because we can fire actions but have them processed by a set of asynchronous middlewares before those actions ever reach a reducer. In the book we build our own toy library around this concept, but for people looking for something to plug into their applications today, the redux-observable is available to plug into redux right out of the box. Using a concept called Epics (I know, one more term) which are essentially just functions that take an Observable and return an Observable, one is able to convert a stream of actions that are created by the store's dispatch method and transform, duplicate, and filter those actions just as we would any other Observable.

This leads to some really clean, independent and easy to test streams like below:



Since the above only handles USER_PROFILE_FETCH actions, it is completely decoupled from the rest of the application, which makes it not only easy to reason about but also easier to test, since we could just plug in a mock source an verify the output. Through the power of Observables we are also able to flatten any number or combination of asynchronous processes into the output stream, and because it operates as middleware, there are no actual changes to the dispatch code, i.e. React or React-Redux.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!