question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m looking for a way of using Most with React, in particular to handle DOM events via React assignment style. Similar solution is presented with RxJS.

My implementation using Most:

function handlerToStream (stream, event) {
  try {
    stream.source.sink.event(performance.now(), event)
  } catch (err) {
    stream.source.sink.error(performance.now(), err);
  }
}

let Button = React.createClass({

  _onClick: handlerToStream.bind(null, (() => {

    let stream = most.create(() => {});
    stream.forEach(event => console.log(event.target));

    return stream;
  })()),
  render() {

    return <button onClick={this._onClick}>click</button>
  }
});

Is there a cleaner way to make this work?

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
TrySoundcommented, Aug 15, 2017

There’s recompose library with configurable utilities compatible with most/rxjs/xstream/flyd/kefir/bacon https://github.com/acdlite/recompose/blob/master/docs/API.md

const RegularComponent = componentFromStream(propsStream =>
  propsStream.map(props =>
    <div>{props.value}</div>
  )
)
const enhance = mapPropsStream(propsStream =>
  propsStream.map(props =>
    Object.assign({}, props, { value: 1 })
  )
)
const RegularComponent = enhance(props =>
  <div>{props.value}</div>
);
const { stream, handler } = createEventHandler();
stream
  .scan((s, a) => s + a, 0)

const dom = <div onClick={() => handler(1)}></div>;
0reactions
briancavaliercommented, Mar 3, 2015

Hey @nissoh, thanks very much for the kind words! I agree: reactive programming is a great way to model highly interactive front-ends. Switching from maintaining shared mutable state, to reactive values where state updates flow through the system is definitely a different way of thinking, but has lots of advantages.

I love the simple programming model you get when using most.js + reactive-dom. There’s practically no shared state to worry about.

i would love to see this fully functional. (:

I’ve been meaning to update that TodoMVC and submit it, but I haven’t had time lately. When you say “fully functional”, do you mean the inline todo editing (I didn’t implement that yet)? Or did you mean something more?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial: Intro to React
React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It lets you compose complex UIs from small and isolated...
Read more >
Getting Started - React
React is a JavaScript library for building user interfaces. Learn what React is all about on our homepage or in the tutorial. Try...
Read more >
React – A JavaScript library for building user interfaces
React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and...
Read more >
Hello World - React
In this guide, we will examine the building blocks of React apps: elements and components. Once you master them, you can create complex...
Read more >
Add React to a Website
Add React in One Minute · Step 1: Add a DOM Container to the HTML · Step 2: Add the Script Tags ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found