All Projects β†’ mmiszy β†’ react-with-observable

mmiszy / react-with-observable

Licence: ISC license
Use Observables with React declaratively!

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-with-observable

observable-profiler
Tracks new & disposed Observable subscriptions
Stars: ✭ 41 (-62.04%)
Mutual labels:  rxjs, observable
recks
🐢 React-like RxJS-based framework
Stars: ✭ 133 (+23.15%)
Mutual labels:  rxjs, jsx
ng-observe
Angular reactivity streamlined...
Stars: ✭ 65 (-39.81%)
Mutual labels:  rxjs, observable
Awesome Rxjs
Awesome list of RxJS 5
Stars: ✭ 141 (+30.56%)
Mutual labels:  rxjs, observable
vanilla-jsx
Vanilla jsx without runtime. HTML Tag return DOM in js, No virtual DOM.
Stars: ✭ 70 (-35.19%)
Mutual labels:  jsx, observable
Jupyterlab Data Explorer
First class datasets in JupyterLab
Stars: ✭ 146 (+35.19%)
Mutual labels:  rxjs, observable
mst-effect
πŸ’« Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (-82.41%)
Mutual labels:  rxjs, observable
Od Virtualscroll
πŸš€ Observable-based virtual scroll implementation in Angular
Stars: ✭ 133 (+23.15%)
Mutual labels:  rxjs, observable
monogram
Aspect-oriented layer on top of the MongoDB Node.js driver
Stars: ✭ 76 (-29.63%)
Mutual labels:  rxjs, observable
rxjs-proxify
Turns a Stream of Objects into an Object of Streams
Stars: ✭ 34 (-68.52%)
Mutual labels:  rxjs, observable
Marble
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS.
Stars: ✭ 1,947 (+1702.78%)
Mutual labels:  rxjs, observable
BittrexRx
BittrexRx is a rxjs node wrapper for the Bittrex Api
Stars: ✭ 16 (-85.19%)
Mutual labels:  rxjs, observable
Redux Most
Most.js based middleware for Redux. Handle async actions with monadic streams & reactive programming.
Stars: ✭ 137 (+26.85%)
Mutual labels:  rxjs, observable
Rx Sandbox
Marble diagram DSL based test suite for RxJS 6
Stars: ✭ 151 (+39.81%)
Mutual labels:  rxjs, observable
Rxjs Hooks
React hooks for RxJS
Stars: ✭ 1,953 (+1708.33%)
Mutual labels:  rxjs, observable
rxrest
Reactive rest library
Stars: ✭ 33 (-69.44%)
Mutual labels:  rxjs, observable
Rxios
A RxJS wrapper for axios
Stars: ✭ 119 (+10.19%)
Mutual labels:  rxjs, observable
React Eva
Effects+View+Actions(React distributed state management solution with rxjs.)
Stars: ✭ 121 (+12.04%)
Mutual labels:  rxjs, observable
rxact
Rxact is an observable application management for Javascript app
Stars: ✭ 21 (-80.56%)
Mutual labels:  rxjs, observable
observe-component
A library for accessing React component events as reactive observables
Stars: ✭ 36 (-66.67%)
Mutual labels:  rxjs, observable

react-with-observable

buddy pipeline codecov cypress dashboard npm npm bundle size (minified + gzip)

react-with-observable: use Observables declaratively in βš›οΈ React!

  • βœ… Supports any Observable implementation compatible with ECMAScript Observable (e.g. RxJS)!
  • βœ… Inspired by the AsyncPipe from Angular!
  • βœ… Very extensible by composing Observable operators!
  • βœ… TypeScript definitions included!

It handles subscribing and unsubscribing automatically and, hence, you don't have to worry about memory leaks or updating state when new values come!

Inspired by the AsyncPipe from Angular. Uses React's create-subscription under the hood.

Install

npm install --save react-with-observable create-subscription

Get a polyfill for Symbol.observable if you need one (you most likely do).

npm install --save symbol-observable

Remember to import 'symbol-observable' before rxjs or react-with-observable!

Usage

The component supports any Observable library compatible with the Observables for ECMAScript draft proposal.

Basics

This package exports a single named component Subscribe. It expects you to provide an Observable as its only child:

const source$ = Observable.of('Hello, world!');
// …
<Subscribe>{source$}</Subscribe>

This results in "Hello, world!" being displayed.

Reactivity

The component automatically updates whenever a new value is emitted by the Observable:

const source$ = Observable.interval(1000);
// …
<Subscribe>{source$}</Subscribe>

As a result, the next integer is displayed every second.

Operators

You can transform the Observable as you wish, as long as the final result is also an Observable:

const source$ = Observable.interval(1000);
// …
<Subscribe>
  {source$.pipe(
    map(val => 10 * val),
    scan((acc, val) => acc + val, 0),
    map(val => <input value={val} />)
  )}
</Subscribe>

As the result, an <input> element is rendered. Its value is changed every second to 0, 10, 30, 60, 100, and so on.

Initial value

Use your Observable library! react-with-observable doesn't implement any custom way to provide the default value and it doesn't need to. For example, with RxJS, you can use the startWith operator:

<Subscribe>
  {source$.pipe(
    startWith(null)
  )}
</Subscribe>

Example

You can find more interactive examples here: https://mmiszy.github.io/react-with-observable/

import 'symbol-observable';
import * as React from 'react';
import { Link } from 'react-router-dom';
import { map, startWith } from 'rxjs/operators';
import { Subscribe } from 'react-with-observable';

// myContacts$ is an Observable of an array of contacts

export class ContactsList extends React.Component {
  render() {
    return (
      <div>
        <h2>My Contacts</h2>
        <Subscribe>
          {myContacts$.pipe(
            startWith(null),
            map(this.renderList)
          )}
        </Subscribe>
      </div>
    );
  }

  renderList = (contacts) => {
    if (!contacts) {
      return 'Loading…';
    }

    if (!contacts.length) {
      return 'You have 0 contacts. Add some!';
    }

    return (
      <ul>
        {contacts.map(contact => (
          <li key={contact.id}>
            <Link to={`/courses/${contact.id}`}>
              {contact.fullName} β€” {contact.description}
            </Link>
          </li>
        ))}
      </ul>
    );
  };
}

Bugs? Feature requests?

Feel free to create a new issue: issues. Pull requests are also welcome!

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].