Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cycle-react

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cycle-react

Rx functional interface to Facebook's React

  • 0.27.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-40%
Maintainers
1
Weekly downloads
 
Created
Source

Cycle-React

Build Status

An RxJS functional interface to Facebook's React.

Cycle-React allows users to write React applications in functional style and represents their UIs as Observables. In addition, Cycle-React is immutable and uses PureRenderMixin internally by default.

Additionally, Cycle-React is also a React-style implementation of a beautiful framework called Cycle.js.

Installing

npm install cycle-react

Example

let Cycle = require('cycle-react');
let React = require('react');

function computer(interactions) {
  return interactions.get('.myinput', 'input')
    .map(ev => ev.target.value)
    .startWith('')
    .map(name =>
      <div>
        <label>Name:</label>
        <input className="myinput" type="text"></input>
        <hr />
        <h1>Hello {name}</h1>
      </div>
    );
}

Cycle.applyToDOM('.js-container', computer);

The input of the computer is interactions, a collection containing all possible user interaction events happening on elements on the DOM, which you can query using interactions.get(selector, eventType).

The output of the computer is Observable<ReactElement> (a reactive sequence of elements, in other words, view).

Function applyToDOM subscribes that Observable of elements and renders the elements to DOM, by using React.createClass and React.render internally.

Notice that although React.createClass is mentioned here, you don't have to use it. That's why Cycle-React was made. We took functions over classes and mutable states.

You can learn more about the concept behind applyToDOM and Cycle from André's amazing presentation: "What if the user was a function?"

Custom element example

let Cycle = require('cycle-react');
let React = require('react');
let Rx = Cycle.Rx;

// "component" returns a native React component which can be used normally
// by "React.createElement" and "Cycle.applyToDOM".
let Counter = Cycle.component('Counter', function (interactions, props) {
  return props.get('counter')
    .map(counter => <h3>Seconds Elapsed: {counter}</h3>);
});

let Timer = Cycle.component('Timer', function () {
  return Rx.Observable.interval(1000).map(i =>
    <Counter counter={i} />
  );
});

Cycle.applyToDOM('.js-container', Timer);
// or
// React.render(
//   React.createElement(Timer),
//   document.querySelector('.js-container'));

Learn more

Cycle-React is a React-style implementation of Cycle.js, so we have the same concept of handling user interactions. More information of this concept can be found at: https://github.com/staltz/cycle

Cycle.js Driver

Starting from Cycle.js v0.23, the driver architecture has been introduced. Cycle-React provides a DOM driver(powered by React, of course) for Cycle.js.

Details can be found at "Using Cycle-React's DOM driver for Cycle.js".

FAQ

Can I use Cycle-React with react-hot-loader?

Yes. And no extra configuration needed.

Example

Can I use Cycle-React with other React components and libraries?

Yes. You can even use Cycle-React with your current React apps. Because component creates the native React component for you.

Examples for integrating Cycle-React with other libraries are work in progress.

Meanwhile, See "Working with React" for guidelines.

Build standalone js

npm run dist

Community

  • Ask "how do I...?" questions in Cycle-React's Gitter:
    Gitter
  • Propose and discuss significant changes as a GitHub issues
  • In addition, more resources can be found at Cycle.js' page

Disclaimer

Work in progress

Just like Cycle.js, changes to API will occur before 1.0.

Keywords

FAQs

Package last updated on 15 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc