Debounce 将在指定的时间间隔过后发出一个值,而不会发出另一个值。
使用简单的图表可以提供更大的帮助:
Stream 1 | ---1-------2-3-4-5---------6----
after debounce, the emitted stream looks like as follows:
Stream 2 | ------1-------------5---------6-
中间项(在本例中为 2、3、4)被忽略。
下面举例说明:
var Rx = require('rx-node');
var source = Rx.fromStream(process.stdin).debounce(500);
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
}
);
我用节点来说明这一点......假设你已经安装了节点,你可以通过键入来运行它
$node myfile.js (where the aforementioned code is in myfile.js)
启动此节点程序后,您可以在控制台输入值——如果您快速输入项目将被忽略,并且如果在控制台输入间隙(在上面的示例中,我有 500 毫秒)后间歇性地输入快速和慢速项目(“下一个: ”)
https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/debounce.md也有一些优秀的参考资料