[英]Reactive extensions Sample or Throttle?
I have a listBox and am observing when items are selected: 我有一个listBox,并观察何时选择项目:
selectedItems.Subscribe(DoWorkWIthSelectedItems);
The observable returns an array of viewModel items and in DoWorkWIthSelectedItems
I go through the list of selected items and do some work. observable返回一个viewModel项的数组,在
DoWorkWIthSelectedItems
我浏览了所选项的列表并做了一些工作。 However, since the user may be spamming selections on/off pretty rapidly, whenever work is done on an item, I don't want any work to be done on that item again for 30 seconds. 但是,由于用户可能会非常快速地打开/关闭选择,每当对某个项目进行工作时,我都不希望再对该项目进行任何工作30秒。 After 30 seconds, if the item is selected again, go ahead and work on it.
30秒后,如果再次选择该项目,请继续操作。
Is there an Rx way to do this? 是否有Rx方式来做到这一点? I am not sure if it would be Sample or Throttle.
我不确定它是Sample还是Throttle。 Furthermore, I don't know if with Rx I am able to distinguish between items in the array that are good to be worked on or should be ignored.
此外,我不知道是否使用Rx我能够区分数组中的项目,这些项目可以用于处理或应该被忽略。 Would I need an additional property on the viewModel item to indicate some 'working' state?
我是否需要viewModel项上的附加属性来指示某些“工作”状态?
Thanks. 谢谢。
No matter what there's going to have to be some state. 不管有什么必须成为一个州。 I think your simplest solution would be something like (pseudocode)
我认为你最简单的解决方案就是(伪代码)
var recentlyUsed = new ConcurrentDictionary<T, DateTime>();
...
selectedItems
.Do(/* remove expired items from recentlyUsed */)
.Where(/* items are not in recently used */)
.Do(/* add items to recently used */)
.Subscribe(DoWorkWIthSelectedItems);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.