【发布时间】:2015-09-02 11:30:09
【问题描述】:
这就是我可以使用 bacon.js 从常规 DOM 节点获取 EventStream 的方法:
var el = document.getElementById('input1');
var stream = Bacon.fromEvent(el, 'input')
当使用 React 时,DOM 节点可能会在一些 render() 迭代后重新创建,因此从真实的 DOM 节点(使用 React.findDOMNode)获取事件不是一种选择。目前我能想到的唯一选择是手动处理事件,然后将它们推送到总线:
var Component = React.createClass({
streams: {},
componentDidMount: function() {
this.streams.inputBus = new Bacon.Bus();
},
componentWillUnmount: function() {
this.streams.inputBus.end();
},
onInput: function(e) {
this.streams.inputBus.push(e);
},
render: function() {
return (
<input type="text" onInput={this.onInput} />
);
}
});
这种方法可以吗,还是有更好的解决方案?
【问题讨论】:
标签: javascript reactjs frp bacon.js