我正在使用combineLatest可观察两个流和选择器函数。RxJS运行选择器功能只有一次
const todos = Rx.Observable.of([{
id: 1,
completed: false,
text: 'one'
}, {
id: 1,
completed: true,
text: 'two'
}]);
const filter = Rx.Observable.of('SHOW_ALL');
const getTodos = Rx.Observable.combineLatest(todos, filter, (todos, filter) => {
console.log('calculation');
// doing some calculation...
return todos;
});
getTodos.subscribe(console.log)
getTodos.subscribe(console.log)
<script src="https://unpkg.com/@reactivex/[email protected]/dist/global/Rx.js"></script>
我需要的结果选择只运行一次同时为用户避免重新计算。例如,如果缓存结果并给我最新的值,如果两个输入都没有改变。
有没有办法用RxJS来做到这一点?
请看看'share'和'publish'运营商:他们专为这种情况。 – dzejdzej
我试过共享运算符,它不适合我。 – undefined
@undefined我不工作怎么样?你能证明你的尝试吗? – martin