npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cycle-react

v7.0.0

Published

Rx functional interface to Facebook's React

Downloads

77

Readme

Cycle-React

Build Status

An RxJS functional interface to Facebook's React.

Cycle-React creates custom React Hooks and allow applications to be written in functional style and control data flow with Observables.

Additionally, Cycle-React is inspired by a beautiful framework called Cycle.js.

Installing

npm install cycle-react react rxjs

React v16.8 or later is required.

Currently, Only RxJS 6 is supported. For migrating RxJS with cycle-react v7, see release note for details.

Example

import React from 'react';
import ReactDOM from 'react-dom';
import { useInteractions } from 'cycle-react';
import { map } from 'rxjs/operators'

const [interactions, useCycle] = useInteractions(
  '', // Initial state
  { // Interaction operators
    onNameChange: map(ev => currentState => ev.target.value)
  }
);

function View() {
  const name = useCycle();
  return (
    <div>
      <label>Name:</label>
      <input type="text"
             onChange={interactions('onNameChange')} />
      <hr />
      <h1>Hello {name}</h1>
    </div>
  );
}

ReactDOM.render(
  <View />,
  document.querySelector('.js-container')
);

interactions is a collection containing all user interaction events happening on the user-defined event handlers on the DOM, which you can define by providing Object.<string, function>. And the event handler for DOM can be defined by interactions.listener(eventName) or simply interactions(eventName).

Function useInteractions subscribes the Observable which is the combination of all interactions merged together, and calls setState from useState(initialState). By connecting interactions and setState, the Observable of user interactions and state changes is completed.

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

From Redux to Cycle-React

Redux | Cycle-React --- | --- Actions | Interactions name Reducers | Interactions operator Store | Interactions object and side-effect from useCycle Provider | createContext - Check example TodoMVC for details. dispatch(action) | interactions(action)

Learn more

Cycle-React is a React-style implementation of Cycle.js, so we have the same concept of handling user interactions. Learn more on: http://cycle.js.org/dialogue.html

In addition, we're working on the documentation site for Cycle-React with more useful examples, too. Stay tuned!

React Native

Example can be found at examples/native

FAQ

What operators are used from RxJS 6?

src/rxjs-adapter.js

Specifically, merge and Subject from rxjs, and scan, startWith from rxjs/operators.

Can I use Cycle-React with Redux?

Not recommended anymore after Cycle-React 7.0. Think Cycle-React as a concise RxJS version of Redux.

Can I host a Cycle-React application in another Cycle-React application?

Nested composition has not supported yet.

Run examples

npm run examples starts an HTTP server that shows examples

Community

  • Ask "how do I...?" questions in Cycle-React's Gitter: Gitter
  • Propose and discuss significant changes as a GitHub issues

Contributions and thanks

  • @cem2ran for adding the support of React Native
  • @corps for implementing the render scheduler feature

License

The MIT License