Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
cycle-react
Advanced tools
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.
npm install cycle-react
let Cycle = require('cycle-react');
let React = Cycle.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.
The description of the concept behind applyToDOM
and Cycle
can be found at
Cycle.js README.
let Cycle = require('cycle-react');
let React = Cycle.React;
let Rx = Cycle.Rx;
// "createReactClass" returns a native react class which can be used normally
// by "React.createElement" and "Cycle.applyToDOM".
let CounterText = Cycle.createReactClass('CounterText',
function (interactions, props) {
return props.get('counter')
.map(counter => <h3>Seconds Elapsed: {counter}</h3>);
}
);
let Timer = Cycle.createReactClass('Timer', function () {
return Rx.Observable.interval(1000).map(i =>
<CounterText counter={i} />
);
});
Cycle.applyToDOM('.js-container', Timer);
// or
// React.render(
// React.createElement(Timer),
// document.querySelector('.js-container'));
You can use h
and without JSX just like you did in Cycle.js.
This was made possible by
react-hyperscript.
The example.
createReactClass
transforms your computer()
function into a ReactClass. So,
you get a ReactClass but without writing a class definition. The point is that
ReactClass is a function indeed and it should always be used as a
function object, because you don't new
, extends
or this
to access
properties. In fact, we don't want you to do that.
Apps written in Cycle-React are this
-less. You won't find a single this
in the examples.
Cycle-React shares the same API as Cycle.js, except of doing custom elements. A more comprehensive README can be found at https://github.com/staltz/cycle
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".
Yes. And no extra configuration needed.
Yes. You can even use Cycle-React with your current React apps. Because
createReactClass
creates the native ReactClass for you.
Examples for integrating Cycle-React with other libraries are work in progress.
Meanwhile, See "Working with React" for guidelines.
npm run dist
Just like Cycle.js, changes to API will occur before 1.0.
0.26.0
Breaking change: Cycle v0.23(or v1.0 API) compatibility changes
var MyComponent = CycleReact.createReactClass('MyComponent',
function (interactions, props) {
var destroy$ = interactions.get('.remove-btn', 'click');
var id$ = props.get('itemid');
// ...
return {
vtree$: Rx.Observable.just(<h3>view</h3>),
destroy$: destroy$,
changeColor$: changeColor$,
changeWidth$: changeWidth$
};
}
);
// Event handler usage
// See docs/interactions.md
<MyComponent onChangeColor$={interactions.subject('onChangeColor').onEvent} />
var MyComponent = CycleReact.createReactClass('MyComponent',
function (interactions, props) {
var destroy$ = interactions.get('.remove-btn', 'click');
var id$ = props.get('itemid');
// ...
return {
view: Rx.Observable.just(<h3>view</h3>),
events: {
destroy: destroy$,
changeColor: changeColor$,
changeWidth: changeWidth$
}
};
}
);
// Event handler usage
// See docs/interactions.md
<MyComponent onChangeColor={interactions.subject('onChangeColor').onEvent} />
Unlike Cycle.js 0.23 which interactions
and props
are replaced by drivers,
Cycle-React keeps these parameters because Cycle-React allows you to create
React components outside the context of Cycle.run
.
Additionally, Cycle-React will keep applyToDOM
and renderAsHTML
for
simple web-app development usage.
Add feature: Cycle.js driver
See docs/cycle-js-driver.md for details.
FAQs
Rx functional interface to Facebook's React
The npm package cycle-react receives a total of 2 weekly downloads. As such, cycle-react popularity was classified as not popular.
We found that cycle-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.