All Projects → milankinen → React Combinators

milankinen / React Combinators

Licence: mit
[NOT MAINTAINED] Seamless combination of React and reactive programming

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Combinators

Awesome Rxjs
A collection of awesome RxJS resources
Stars: ✭ 314 (+230.53%)
Mutual labels:  reactive-programming, observables
servable
"simple" observable implementation based off RxJS & kefir Docs
Stars: ✭ 14 (-85.26%)
Mutual labels:  reactive-programming, observables
Learn Rxjs
Clear examples, explanations, and resources for RxJS
Stars: ✭ 3,475 (+3557.89%)
Mutual labels:  reactive-programming, observables
Toy Rx
A tiny implementation of RxJS that actually works, for learning
Stars: ✭ 290 (+205.26%)
Mutual labels:  reactive-programming, observables
Inferno Most Fp Demo
A demo for the ReactJS Tampa Bay meetup showing how to build a React+Redux-like architecture from scratch using Inferno, Most.js, reactive programmning, and various functional programming tools & techniques
Stars: ✭ 45 (-52.63%)
Mutual labels:  reactive-programming, observables
Karet
Karet is a library that allows you to embed Kefir observables into React VDOM
Stars: ✭ 81 (-14.74%)
Mutual labels:  observables
Plum
A deployer library for PHP 5.3
Stars: ✭ 88 (-7.37%)
Mutual labels:  deprecated
Reactiveandroid
Reactive events and properties with RxJava for Android
Stars: ✭ 80 (-15.79%)
Mutual labels:  reactive-programming
Ease
It's magic.
Stars: ✭ 1,213 (+1176.84%)
Mutual labels:  observables
Gphotos Sync
DEPRECATED - Google Photos Simple Synchronization Tool
Stars: ✭ 94 (-1.05%)
Mutual labels:  deprecated
Notifier For Github Safari
Safari extension - Displays your GitHub notifications unread count
Stars: ✭ 90 (-5.26%)
Mutual labels:  deprecated
Codeigniter Schema
⛔️DEPRECATED Expressive table definitions
Stars: ✭ 87 (-8.42%)
Mutual labels:  deprecated
Angular2 Style Guide
[Deprecated] Community-driven set of best practices and style guidelines for Angular 2 application development
Stars: ✭ 1,237 (+1202.11%)
Mutual labels:  deprecated
Gulp Ngmin
[DEPRECATED] Pre-minify AngularJS apps with ngmin
Stars: ✭ 89 (-6.32%)
Mutual labels:  deprecated
Vagrant Librarian Chef
*UNMAINTAINED* A Vagrant plugin to install Chef cookbooks using Librarian-Chef.
Stars: ✭ 80 (-15.79%)
Mutual labels:  deprecated
Lda Topic Modeling
A PureScript, browser-based implementation of LDA topic modeling.
Stars: ✭ 91 (-4.21%)
Mutual labels:  reactive-programming
Graphql Rxjs
fork of Graphql which adds Observable support
Stars: ✭ 78 (-17.89%)
Mutual labels:  observables
Spring 5 Examples
This repository is contains spring-boot 2 / spring framework 5 project examples. Using reactive programming model / paradigm and Kotlin
Stars: ✭ 87 (-8.42%)
Mutual labels:  reactive-programming
Reactive Stock Trader
A Stock Trader system to demonstrate reactive systems development
Stars: ✭ 90 (-5.26%)
Mutual labels:  reactive-programming
Jasmine Marbles
Marble testing helpers for RxJS and Jasmine
Stars: ✭ 85 (-10.53%)
Mutual labels:  observables

React Combinators

Seamless combination of React and reactive programming with (RxJs / Kefir / Bacon.js).

npm version Build Status

THIS LIBRARY IS NOT MAINTAINED ANYMORE

If you are interested in doing applications with React and observables, please see:

  • calmm-js powerful toolset for state management and rendering with React and observables (Kefir & Bacon atm)
  • react.reactive calmm-js rendering part extracted and made streaming library agnostic

Motivation

Modeling your application state with observables gives you powerful tools for (async) state handling. However, combining those observables with React UIs has been a difficult: every observable must be subscribed and disposed separately with the component's lifecycle hooks. Such boilerplate!

The goal of this project is to enable seamless combination of React and observable by introducing React Observable Combinators. Say hello to truly reactive and declarative React app development!

Example

Reddit post search implemented with combinators and kefir (counter example would have been too easy):

import React from "react"
import Kefir from "kefir"
import {Combinator} from "react-combinators/kefir"
import {render} from "react-dom"

// lets define our reactive Reddit state model, see Kefir
// docs for more info about pools and other used methods
function Reddit(initial) {
  const pool = Kefir.pool()
  const setReddit = reddit => pool.plug(Kefir.constant(reddit))
  const reddit =
    pool.merge(Kefir.constant(initial)).toProperty()
  const posts =
    reddit
      .flatMapLatest(reddit => Kefir.fromPromise(
        fetch(`http://www.reddit.com/r/${reddit}.json`).then(req => req.json())
      ))
      .map(json => json.data.children.map(({data}) => data))
      .merge(Kefir.constant([])) // initial value
      .toProperty()
  const loading =
    reddit.map(() => true).merge(posts.map(() => false)).toProperty()

  // yes. the model is just a plain object with a set of actions
  // and reactive properties
  return { reddit, posts, loading, setReddit }
}

// no containers are needed! observables and combinators handle that the
// UI syncs with the state
function App({model}) {
  const { reddit, posts, loading, setReddit } = model

  // we can derive properties as well
  const loadingIndicator =
    loading.map(loading => loading ? <img src="spinner.gif" /> : null)

  // all you need to do is to surround your JSX with <Combinator> element
  return (
    <Combinator>
      <div>
        Select Reddit:
        <select value={reddit} onChange={e => setReddit(e.target.value)}>
          <option value="reactjs">/r/reactjs</option>
          <option value="javascript">/r/javascript</option>
          <option value="ReactiveProgramming">/r/ReactiveProgramming</option>
        </select>
        {loadingIndicator}
        <hr />
        <ul>
          {posts.map(posts => posts.map(post => (
            <li>{post.title}</li>
          )))}
        </ul>
      </div>
    </Combinator>
  )
}

const myReddit = Reddit("ReactiveProgramming")
render(<App model={myReddit} />, document.getElementById("app"))

Installation

npm i --save react react-combinators <your-frp-library>

Currently supported FRP libraries are

  • rx
  • baconjs
  • kefir

API

All API functions and components are implemented for each supported FRP library and they are accessible through:

const {<functions/components...>} = require("react-combinators/<your-frp-library>")

<Combinator>

Higher order component that "wraps" the observables from its children and returns a virtual dom element that gets updated by changes in any of its child elements. Combinator components should be used at the top-level of your React component.

Usage:

import {Combinator} from "react-combinators/<your-frp-library>"

function MyApp(observable) {
  return (
    <Combinator>
      <span>My observable value: {observable}</span>
    </Combinator>
  )
}

combineVDOM

Higher order function that transforms a virtual dom tree containing observables to an observable that returns the same virtual dom where the observables are replaced with their values. Same as combine* functions in FRP libraries but this one is optimized for virtual dom.

Usage (example with Bacon.js):

const a = Bacon.constant(10)
const b = Bacon.constant(20)
const vdom = combineVDOM(
  <div>{a} + {b} = {Bacon.combineWith(a, b, (a, b) => a + b)}</div>
)
console.log(vdom instanceof Bacon.Property)  // => true

createComponent

Creates a reactive component which wraps its observables into React.Component, hence it can be mixed with normal react components.

createComponent takes one function which receives the component's properties as observables and returns an observable containing the rendered virtual dom.

Signature:

createComponent :: ({propsObservales} => Observable(VDOM)) => React.Component

Usage (example with Bacon.js):

const Example = createComponent(({a, b}) => {
  const c = Bacon.combineWith(a, b, (a, b) => a + b)
  return combineVDOM(
    <div>{a} + {b} = {c}</div>
  )
})

// ... somewhere in your app...
<div>
  Example: <Example a={10} b={20} />
</div>

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].