damgate
v2.0.1
Published
Damming up and releasing out flowing events with some conditional patterns.
Downloads
293
Readme
damgate
Damming up and releasing out flowing events with some conditional patterns.
// Pass through 2 events per second
var dam = new FirstDamGate( /*fps=*/2 )
$(window).scroll(function(){
dam.execute(function(){
console.log("Dammed scroll!!")
})
})
FirstDamGate
This dam is useful for simple event filtering.
Pass through the first event and then the dam is closed.
After an interval dam is opened again.
LastDamGate
This dam passes through the last event if no latest event is arrived within the interval.
This is useful for a case like firing text search api on form change events.
Here is the reactjs example.
var dam = new LastDamGate( /*fps=*/0.6 )
var KeywordInput = React.createClass({
getInitialState: function(){
return { text: "" }
},
handleChange: function(event) {
this.setState({ text: event.target.value })
dam.execute(function(){
search(event.target.value)
})
}
render: function() {
return (
<input
type="text"
value={this.state.text}
onChange={this.handleChange} />
)
}
})