Git Product home page Git Product logo

aicarumba's Introduction

Redux-Observable example

This example is a page that renders information about Star-Wars characters. It fetches new character every 3 seconds having the initial character fetched on a server.

Example also uses redux-logger to log every action.

Deploy your own

Deploy to Netlify Button

Note: we are not using AjaxObservable from the rxjs library; as of rxjs v5.5.6, it will not work on both the server- and client-side. Instead we call the default export from universal-rxjs-ajax (as request).

We transform the Observable we get from ajax into a Promise in order to await its resolution. That resolution should be a action (since the epic returns Observables of actions). We immediately dispatch that action to the store.

This server-side solution allows compatibility with Next. It may not be something you wish to emulate. In other situations, calling or awaiting epics directly and passing their result to the store would be an anti-pattern. You should only trigger epics by dispatching actions. This solution may not generalise to resolving more complicated sets of actions.

The layout of the redux related functionality is split between:

- actions (in `redux/actions.ts`)
- actionTypes (in `redux/actionTypes.ts`)
- epics (in `redux/epics.ts`)
- reducer (in `redux/reducer.js`)

and organized in redux/index.tsx.

Excepting in those manners discussed above, the configuration is similar the configuration found in with-redux example and redux-observable docs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.