• This repository has been archived on 11/Jan/2019
  • Stars
    star
    286
  • Rank 143,761 (Top 3 %)
  • Language
    JavaScript
  • License
    Creative Commons ...
  • Created almost 9 years ago
  • Updated over 7 years ago

Reviews

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

Repository Details

[UNMAINTAINED] Reactive state and side effect management for React using a single stream of actions

Flexible state and side effect manager using RxJS for React.

Join Fluorine's Slack!

About

Fluorine provides you with easy, reactive state and side effect management, accumulating stores from streams of actions and side effects.

It builds on the ideas of Redux, while preserving a Flux-like Dispatcher as the single source of truth.

  • Your stores are directly reduced from the dispatcher and actions are dispatched on it
  • Manage your side effect as Observables ("Agendas") with automatic rollbacks on error
  • Unopinionated and simple API with Middleware support

This is the ultimate way to use RxJS for state and side effect management!

Documentation

Quick Intro

This is just a short example that quickly presents all features of the Dispatcher. It is of course not representetive for how to use it in real React projects.

import { createDispatcher } from 'fluorine-lib'
import thunk from 'fluorine-lib/lib/middleware/thunk'

/**
 * This is a reducer, a pure function with (state, action) => state signature.
 * It describes how an action transforms the state into the next state.
 *
 * The shape of the state is up to you: it can be a primitive, an array, an object,
 * or even an Immutable.js data structure. The only important part is that you should
 * not mutate the state object, but return a new object if the state changes.
 *
 * In this example, we use a `switch` statement and strings, but you can use a helper that
 * follows a different convention (such as function maps) if it makes sense for your project.
 */
function counter(state = 0, action) {
  switch (action.type) {
  case 'INCREMENT':
    return state + 1
  case 'DECREMENT':
    return state - 1
  default:
    return state
  }
}

// Create a dispatcher which is our event stream
const dispatcher = createDispatcher({ logging: true }, [ thunk ])

// This reduces the dispatcher event stream to a store. This is essentially an
// RxJS Observable that emits the state of the store over time
const store = dispatcher.reduce(counter)

store.subscribe(x => {
  console.log(x) // Your store's state
})

// Dispatch an action, a thunk, or a promise

dispatcher.next({ type: 'INCREMENT' })

dispatcher.next(next => {
  next({ type: 'DECREMENT' })
})

dispatcher.next(new Promise((resolve, reject) => {
  resolve({ type: 'INCREMENT' })
}))

// Agendas: Schedule a task, represented by an observable that emits actions
// If the observable fails, then all its changes are reverted

const addIfFetchSucceeds = Observable
  .of({ type: 'ADD' })
  .concat(Observable
    .of('/ping')
    .flatMap(path => Observable.fromPromise(fetch(path))))

dispatcher.next(addIfFetchSucceeds)

Just as in Flux we've got stores, actions and a dispatcher. The seperation of concern is intact, while the dispatcher exclusively is the single source of truth.

Compared to Redux we've got fully functional actions and stores as well, but the state is handled fully reactively using RxJS. We can even use all of RxJS's operators.

On top of that we've got a new way of handling side effects: Agendas. This enables you to schedule observables as streams of actions, which roll back all their changes if they fail. This makes it easy to design exceedingly complex side effects.

Fluorine-related Projects

Frequently Asked Questions

Why write another Flux library?

The goal of this project is to create a efficient but minimal library on top of RxJS that can preserve your previous (pure reducer) stores and actions, which you would write for a Redux project as well, but give you even more power over them.

Redux is building on top of the known strengths of Flux by mixing it with more functional ideas, but without a tool like RxJS it fails to combine the dispatcher and stores. Fluorine doesn't need containers for stores as every store can be reduced from the actions on the Dispatcher reactively.

On top of that Fluorine provides a new way to manage side effects, which is much more powerful than plain thunks.

Why the name?

Fluorine is (chemically-speaking) the most reactive non-metal. As Fluorine embraces RxJS to bring even more advantages of reactive programming to React, it is a fitting name.

Furthermore the latin verb fluo means "flow", which is a direct refernce to Flux and its unidirectional data-flow.

Used and Supported by

DataWallet

Thanks to

  • The ReactiveX team, all the RxJS developers and the ReactiveX community
  • Dan Abramov for Redux that is a big influence to Fluorine
  • The React team

More Repositories

1

setup-simple-ipsec-l2tp-vpn

Setup a simple IPSec/L2TP VPN Server for Ubuntu and Debian
Shell
644
star
2

setup-strong-strongswan

[UNMAINTAINED] Setup a (really) strong StrongSwan VPN Server for Ubuntu and Debian
Shell
633
star
3

sweetsour

A CSS-in-JS parser and pipeline adhering to the ISTF spec 🍭
OCaml
224
star
4

docker-strongswan

Docker image for easily setting up a secure StrongSwan VPN
Shell
178
star
5

prosemd-lsp

An experimental proofreading and linting language server for markdown files ✍️
Rust
142
star
6

rxjs-diagrams

React Components for visualising RxJS observables and operators
JavaScript
128
star
7

spectacle-sync

πŸ’ Present Spectacle presentations synchronised on multiple devices
JavaScript
59
star
8

extendable-immutable

Wrapper classes around Immutable.js that turn it inheritable
JavaScript
58
star
9

bunpkg

A proof of concept clone of Unpkg running on Cloudflare Workers
TypeScript
49
star
10

stream-tag

A tagged template literal utility for Node streams
TypeScript
47
star
11

react-compat-component

Marrying ES6 with mixins and more: Compatibility layer for React's ES6 Component class
JavaScript
39
star
12

Adventurous-Syntax

A dark Atom theme using common colors often seen in the cult series Adventure Time.
CSS
28
star
13

react-wonka

Several hooks for using Wonka streams with React
TypeScript
26
star
14

moomin

An experimental JSX/component framework around Reprocessing for Reason
OCaml
17
star
15

graphql-box

[WIP] Instant GraphQL OpenCRUD database that is universally runnable & deployable
TypeScript
17
star
16

pessimism

A fast HAMT Map intended for KV caching and optimistic updates
OCaml
15
star
17

bs-rebel

A toolkit for collections for bsb-native and bsb aimed at bundle size and performance
OCaml
14
star
18

kitten.sh

My collection of posts as found at kitten.sh
JavaScript
12
star
19

redux-fluorine

A Redux enhancer to manage groups of actions as observables ("agendas")
JavaScript
12
star
20

hachiko

WIP: Modular and performant data collections for JavaScript
TypeScript
10
star
21

bs-flow-parser

Flow's JavaScript parser, packaged and adapted for BuckleScript
OCaml
10
star
22

runruntypes

A poor man's runtime-only type checker
JavaScript
9
star
23

system

Nix
9
star
24

vim-adventurous

A dark vim color theme using common colours often seen in the cult series Adventure Time
Vim Script
9
star
25

react-static-plugin-md-pages

react-static plugin to create nested pages from a given source directory
JavaScript
7
star
26

goethe

Node module for immutable color conversion and manipulation
JavaScript
6
star
27

dotfiles

Vim Script
6
star
28

2g

WIP: A cross-platform creative coding framework for Reason
C
6
star
29

didsmoosh

componentDidSmoosh is a comedy night for JS nerds bringing together experts of developer humour on stage
JavaScript
6
star
30

fix-ubuntu-unicorn-for-macbooks

A wizard which can fix multiple issues, bugs and quirks occuring on Macbook Pros running Ubuntu 14.10.
Shell
5
star
31

nightingale

Reason
4
star
32

reason-hmm

HandmadeMath Bindings for OCaml
C++
4
star
33

reason-glsl-optimizer

GLSL Optimizer Bindings for OCaml
C++
4
star
34

threed-example-api

A GraphQL Example API for threaded conversations
JavaScript
4
star
35

advent-of-code-2019

Learning some Rust with "Advent of Code 2019" β€” because why not?
Rust
4
star
36

bowtie

JavaScript
4
star
37

thought-leader

JavaScript
3
star
38

concurrent-mode-deck

JavaScript
3
star
39

gatsby-theme-docs-system

JavaScript
3
star
40

twitter-was-down-

2
star
41

gatsby-theme-mdx-deck

Modified version of mdx-deck's Gatsby Theme with fixed size slides
JavaScript
2
star
42

vierdreidrei

433Mhz Receiver and Transmitter Module through a RCSwitch wrapper (WIP)
C++
1
star
43

pebble-barely-v2

A simple watchface only using horizontal and vertical straight lines for the Pebble smartwatch. Four squares for the time, four for the date, and four for the year, filling the whole screen. Also invertable!
C
1
star
44

kitten

1
star