Skip to content

Instantly share code, notes, and snippets.

@roman01la
Created January 26, 2015 14:06
Show Gist options
  • Save roman01la/40a7e873a8085f8ebabe to your computer and use it in GitHub Desktop.
Save roman01la/40a7e873a8085f8ebabe to your computer and use it in GitHub Desktop.
Mixin for handling DOM events via React assignment style using Most
import React from 'react';
import ReactDOMMostify from 'react-dom-mostify';
let Button = React.createClass({
mixins: [ReactDOMMostify],
componentWillMount() {
let clicks = this.mostifyEventHandler('_onClick');
clicks.forEach(console.log.bind(console));
},
render() {
return <button onClick={this._onClick}>Click!</button>;
}
});
React.render(<Button />, document.body);
import most from 'most';
let ReactDOMMostify = {
mostifyEventHandler (name) {
let emitEvent, stream;
emitEvent = () => undefined;
this[name] = event => emitEvent(event);
stream = most.create(add => emitEvent = add);
stream.drain();
return stream;
}
};
export default ReactDOMMostify;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment