Rx突破性变化

时间:2011-10-11 18:20:36

标签: system.reactive

我知道SL5有一个新的属性来统计MouseClicks,但是在SL4出来的帮助下,我得到了这个功能。现在我转移到一台新机器,下载了RX,我理解RX经历了一些破坏了这段代码的变化。我试过了,但我似乎无法从FastSubject转换过来。

我真的想完全理解这里使用Subject,以及如何更新调用以使用当前版本的Rx。

public static IObservable<TSource> MonitorForDoubleClicks<TSource>(this IObservable<TSource> source, TimeSpan doubleClickSpeed, IScheduler scheduler)
{
  return source.Multicast<TSource, TSource, TSource>(
      () => new FastSubject<TSource>(), 
      values =>
      {
        return values
            .TimeInterval(scheduler)  //injects a timestamp event arguments
            .Skip(1)                  // in order to determine an interval we need two of these, so this keeps the event in the collection, but does not process the first one in
            .Where(interval => interval.Interval <= doubleClickSpeed)     //second event has arrived, so we can test the interval
            .RemoveTimeInterval()                                         //take the time argument out of the event args
            .Take(1)                                                      //we take one of the events (the latest) and throw it
            .Repeat();                                                    //keep the observer alive forever
      });

1 个答案:

答案 0 :(得分:2)

FastSubject现在只是主题,所有主题都很快:)但是,这是检查双击的奇怪方法。

如何(警告:通过TextArea编码):

return source.Timestamp(scheduler)
    .Buffer(/*buffer of*/2, 1 /*advanced at a time*/)
    .Where(x => x[1].Timestamp - x[0].Timestamp < doubleClickSpeed)
    .Select(x => x[1]);