Rx突破性的变化



我知道SL5有一个新的属性来计算mouseclick,但是在帮助下,当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
      });

FastSubject现在只是Subject,所有科目都是快速的:)然而,这是一种奇怪的方式来检查双击。

不如这样写(warning: Coding via 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]);

相关内容

  • 没有找到相关文章

最新更新