Last active
August 29, 2015 14:04
-
-
Save brandonbloom/56be8fcd4989f7396a1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsx React.DOM */ | |
var Bubbler = React.createClass({ | |
render: function() { | |
return <input type="button" onClick={this.props.onFoo} value="Click me"/>; | |
} | |
}); | |
var Handler = React.createClass({ | |
onFoo: function() { | |
alert("handled!"); | |
}, | |
render: function() { | |
return <Bubbler onFoo={this.onFoo}/>; | |
} | |
}); | |
React.renderComponent(<Handler/>, document.body); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsx React.DOM */ | |
var Bubbler = React.createClass({ | |
render: function() { | |
return <input type="button" onClick={this.props.onFoo} value="Click me"/>; | |
} | |
}); | |
var Handler = React.createClass({ | |
effects: { | |
foo: function() { | |
alert("handled!"); | |
} | |
}, | |
render: function() { | |
return <Bubbler onFoo={this.effects.foo}/>; | |
} | |
}); | |
React.renderComponent(<Handler/>, document.body); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsx React.DOM */ | |
var Bubbler = React.createClass({ | |
render: function() { | |
return <input type="button" onClick={this.props.onFoo} value="Click me"/>; | |
} | |
}); | |
var Handler = React.createClass({ | |
handlers: function() { | |
return [ | |
[this.props.eff, function() { | |
alert("handled!"); | |
}] | |
]; | |
}, | |
render: function() { | |
return this.props.children; | |
} | |
}); | |
var Wrapper = React.createClass({ | |
effects: { | |
foo: newEffect() | |
}, | |
render: function() { | |
return <Handler eff={this.effects.foo}><Bubbler onFoo={this.effects.foo}/></Handler> | |
} | |
}); | |
React.renderComponent(<Wrapper/>, document.body); |
I ended up implementing the range thing I was talking about https://davidbruant.github.io/inline-range-demo/ Click on the number and drag left and right to increase/decrease the value.
It can be implemented in React, but in a way that is more elegant in my opinion, because of the lack of a proper event system.
It's really matter of calling the handleMouseMove
method and testing for this.state.dragging
; it's probably less performent, but not that much I think (though I'm not sure). This could probably be microbenchmarked, oh well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sounds complicated… Is this for performance reason? Anyway you're right, there's no obvious way to achieve this using event listeners passed as attributes in React. I'm just challenging the idea of this need being mainstream enough for the team to work on this… Honestly, I don't have a clue.