2015-09-02 36 views
2

這是我怎樣才能從一個普通的DOM節點與bacon.js的EventStream:獲取EventStream反應,培根

var el = document.getElementById('input1'); 
var stream = Bacon.fromEvent(el, 'input') 

當使用反應,DOM節點可以經過一些重新渲染( )迭代,因此從真正的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} /> 
    ); 
    } 
}); 

是這種方法確定,或者有什麼更好的辦法呢?

回答