Rxjs 不同的和数字数组
Rxjs distinct and arrays of numbers
我无法向自己解释这个
const something = new Rx.BehaviorSubject([1,2,4,4])
.distinct()
.do((s) => console.log(s))
.map(list => list.length)
.filter(length => length >=2)
.subscribe(total => console.log('total:', total));
这是我得到的输出
[1, 2, 4, 4]
"total:"
4
我很困惑,因为查看 distinct 上的文档时我认为它适用于数字。我的用例是一个数据 table 小部件向我发送事件,这个数组跟踪他们单击了哪一行,我想检测一次双击发生。
更新代码
const something = new Rx.BehaviorSubject([]);
something.next([1]);
console.log(something.getValue());
something.next(something.getValue().concat(2));
something.next(something.getValue().concat(3));
something.next(something.getValue().concat(4));
something.next(something.getValue().concat(4));
某事
。清楚的()
.subscribe(val => console.log('value:', val));
输出
"value:"
[1, 2, 3, 4, 4]
您发送的值恰好是一个数组。如果你这样做,你会看到 distinct 的操作
const something = new Rx.BehaviorSubject([]);
something .distinct() .subscribe(val => console.log('value:', val));
something.next(1); // --> value: 1
something.next(2); // --> value: 2
something.next(1); // no output (because of distinct)
something.next(3); // --> value: 3
我无法向自己解释这个
const something = new Rx.BehaviorSubject([1,2,4,4])
.distinct()
.do((s) => console.log(s))
.map(list => list.length)
.filter(length => length >=2)
.subscribe(total => console.log('total:', total));
这是我得到的输出
[1, 2, 4, 4]
"total:"
4
我很困惑,因为查看 distinct 上的文档时我认为它适用于数字。我的用例是一个数据 table 小部件向我发送事件,这个数组跟踪他们单击了哪一行,我想检测一次双击发生。
更新代码
const something = new Rx.BehaviorSubject([]);
something.next([1]); console.log(something.getValue()); something.next(something.getValue().concat(2)); something.next(something.getValue().concat(3)); something.next(something.getValue().concat(4)); something.next(something.getValue().concat(4));
某事 。清楚的() .subscribe(val => console.log('value:', val));
输出
"value:"
[1, 2, 3, 4, 4]
您发送的值恰好是一个数组。如果你这样做,你会看到 distinct 的操作
const something = new Rx.BehaviorSubject([]);
something .distinct() .subscribe(val => console.log('value:', val));
something.next(1); // --> value: 1
something.next(2); // --> value: 2
something.next(1); // no output (because of distinct)
something.next(3); // --> value: 3