• Stars
    star
    421
  • Rank 102,977 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A reimplementation of redux using RxJS.

npm version

rx-redux

A reimplementation of redux using RxJS.

Why?

Reactive by default, this makes difference.

If you just want to use redux with RxJS and don't care about API compatibility, see redux-core.

Features

  • All of the redux APIs implemented.
  • Additionally, store provides 2 rx objects you can utilize:
    • dispatcher$ is a Subject that you can pass actions in.
    • state$ is an Observable, a stream of states.
  • And a helper function connectAction to stream actions to store (see example below).

What does it look like?

import {createStore, combineReducers, applyMiddleware, connectAction} from 'rx-redux'
import thunkMiddleware from 'redux-thunk'
import * as reducers from './reducers'
import { render, getActionStream } from './view'

const action$ = getActionStream();

const newCreateStore = applyMiddleware(thunkMiddleware)(createStore);
const reducer = combineReducers(reducers);
const store = newCreateStore(reducer);

// stream states to view
store.state$.subscribe(state => render(state));

// stream actions to dispatcher
action$.subscribe(action => store.dispatcher$.onNext(action));
// or you can write this way
// connectAction(action$, store);

Best practice to make your app all the way reactive

Don't do async in Middleware, create RxMiddleware instead.

This will ease the pain to build universal apps.

RxMiddleware

Which wraps action stream, look like this:

import Rx from 'rx';

export default function thunkMiddleware(getState) {
  return action => {
    if(typeof action === 'function') {
      return Rx.Observable.just(action(getState));
    }

    // Don't know how to handle this thing, pass to next rx-middleware
    return Rx.Observable.just(action);
  };
}

How to design RxMiddleware

  • Get action, return Observable.
  • Must return Observable.
    • If you don't want to return an action (eg. if counter is not odd), return a Rx.Observable.empty().

See a basic RxMiddleware example

WIP

  • Figure out how to test a Rx project (No experience before).
  • Work with Hot Module Replacement.
  • Work with redux-devtools.
  • More examples.

Thanks

  • @xgrommx for submitting pull requests and suggestions.

Feel free to ask questions or submit pull requests!

Inspiration

  • redux, learn a lot through the source code.
  • Cycle.js for the cool MVI flow.

License

The MIT License (MIT)

More Repositories

1

thisless-react

Reactive React application flow with React, RxJS and Redux
257
star
2

atom-live-server

Launch a simple development http server with live reload capability.
JavaScript
121
star
3

react-reactive-class

Reactive React components
JavaScript
44
star
4

redux-core

Minimal redux
JavaScript
42
star
5

karma-sourcemap-writer

Sourcemap writer for karma.
JavaScript
24
star
6

elm-architecture

The Elm Architecture in JavaScript
JavaScript
16
star
7

react-dnd-card

Create a drag and drop list in a minute. Built on top of React DnD.
JavaScript
12
star
8

react-starter-kit

React Starter Kit
JavaScript
7
star
9

json-parse

Adds syntax highlighting for JSON.parse(tagged template strings).
4
star
10

react-render-loader

A webpack loader that renders React components to HTML strings.
JavaScript
4
star
11

router5-link-interceptor

Link interceptor for router5.
JavaScript
4
star
12

unbloat

Atomic CSS in JS
JavaScript
4
star
13

simple-universal-web-app

Dead simple, no router and other stuff. Only to show how universal web apps work.
JavaScript
4
star
14

evstore

Event based state management library
JavaScript
3
star
15

clex

Switch-case free state management library
JavaScript
3
star
16

undo-redo-demo

undo redo 大作戰
HTML
2
star
17

srender

Tiny web framework
JavaScript
2
star
18

default-css-class-loader

BEM style like CSS naming conventions with CSS Modules made easy.
JavaScript
1
star
19

jas-chen.github.io

HTML
1
star
20

css-in-js

CSS in JS techniques - Version and Downloads.
1
star
21

tomcat6-jre7-ssl-admin

Tomcat 6 with SSL and Admin user configuration
Shell
1
star
22

vueactive

React bindings for @vue/reactivity
JavaScript
1
star
23

rescript-create-react-app

Create React App with ReScript
HTML
1
star
24

jsty

Fast and tiny CSS in JS library
TypeScript
1
star