• Stars
    star
    138
  • Rank 264,508 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Redux-clone build with strict typing and RxJS down to its core. Wrist-friendly, no boilerplate or endless switch statements

Build Status npm version code coverage

Reactive State

A typed, wrist-friendly state container aimed as an alternative to Redux when using RxJS. Written with RxJS in TypeScript but perfectly usable from plain JavaScript. Originally inspired by the blog posting from Michael Zalecki but heavily modified and extended since.

Features

  • type-safe actions: no boilerplate code, no mandatory string constants, and not a single switch statement
  • Actions are just Observables, so are Subjects. Just call .next() to dispatch an action.
  • dynamically add and remove reducers during runtime
  • no need for async middlewares such as redux-thunk/redux-saga; actions are Observables and can be composed and transformed async using RxJS operators
  • no need for selector libraries like MobX or Reselect, RxJS already ships it
  • single, application-wide Store concept as in Redux. Possibility to create slices/substates for decoupling (easier reducer composition and state separation by module)
  • Strictly typed to find errors during compile time
  • Heavily unit tested, 100+ tests for ~250 lines of code
  • React bridge (like react-redux) included, though using React is not mandatory
  • Support for React-Devtool Extension

Installation

npm install reactive-state

Documentation

Additionally, there is a small example.ts file and see also see the included unit tests as well.

Example Usage

import { Store } from "reactive-state";
import { Subject } from "rxjs";
import { take } from "rxjs/operators";

// The state for our example app
interface AppState {
    counter: number;
}

const initialState: AppState = { counter: 0 }

const store = Store.create(initialState);

// The .watch() function returns an Observable that emits the selected state change, so we can subscribe to it
store.watch().subscribe(newState => console.log("STATE:", JSON.stringify(newState)));

// the watch() observable always caches the last emitted state, so we will immediately print our inital state:
// [CONSOLE.LOG]: STATE: {"counter":0}

// use a RxJS Subjects as an action
const incrementAction = new Subject<number>();

// A reducer is a function that takes a state and an optional payload, and returns a new state
function incrementReducer(state, payload) {
    return { ...state, counter: state.counter + payload };
};

store.addReducer(incrementAction, incrementReducer);

// lets dispatch some actions

incrementAction.next(1);
// [CONSOLE.LOG]: STATE: {"counter":1}
incrementAction.next(1);
// [CONSOLE.LOG]: STATE: {"counter":2}

// async actions? No problem, no need for a "middleware", just use RxJS
interval(1000).pipe(take(3)).subscribe(() => incrementAction.next(1));
// <PAUSE 1sec>
// [CONSOLE.LOG]: STATE: {"counter":3}
// <PAUSE 1sec>
// [CONSOLE.LOG]: STATE: {"counter":4}
// <PAUSE 1sec>
// [CONSOLE.LOG]: STATE: {"counter":5}

License

MIT.

More Repositories

1

mdwiki

CMS/Wiki system using Javascript for 100% client side single page application using Markdown.
JavaScript
3,109
star
2

JsonConfig

simple configuration library using JSON and C# 4.0 dynamic feature
C#
202
star
3

Rainy

Simple Tomboy/Tomdroid cloud/syncing server. Written in C# with AngularJS web frontend. Supports SQLite & Postgres Backends.
JavaScript
87
star
4

mdwiki-seed

Basic template file layout to start with MDwiki - see http://mdwiki.info
26
star
5

tcp_probe_fixed

Bugfixed & modified version of tcp_probe.c linux kernel module to monitor congestion/flow control of tcp connections
C
25
star
6

mdwiki-examples

A collection of example wesbites created with MDwiki
23
star
7

redux-pattern-with-rx

Basic Redux implementation in RxJS. For educational and production use
TypeScript
14
star
8

reactive-state-react-example

A full React Counter/Todo application using reactive-state as a Container plus RxJS instead of Redux
TypeScript
6
star
9

genbanking

A simple framework for common banking tasks with webservice access through SOAP and JSON. Currently support german Bankaccount via HBCI
C#
5
star
10

PortableIoC

Single .cs file IoC container for .NET/PCL. Fork from portableioc.codeplex.com
C#
4
star
11

banshee-osx

My local mirror for banshee on OS X to work during my GSoC
C#
2
star
12

tomboy-sync-example

Example of how to use Tomboy-library to sync with a a WebSync Server such as Rainy
C#
2
star
13

MarkdownSharp

Fork from the google-code hosted MarkdownSharp at http://code.google.com/p/markdownsharp/
C#
2
star
14

aqbankingNET

A common language runtime (CLR) wrapper for aqbanking that allows usage of the C/C++ aqbanking library from C# and other .NET languages using mono on Linux/UNIX and possible windows.
2
star
15

autobahn-ts

TypeScript fork/port of the original autobahnJS library
JavaScript
1
star
16

jquery-lazy-gist

a jQuery plugin that will lazy load your gists.
JavaScript
1
star
17

coffeeloader

A node.js based http server that dynamically compiles and conditionally assembles Coffeescript and Javascript using configured profiles
CoffeeScript
1
star