2011-10-11 63 views
1

我知道SL5有一個新的屬性來計算MouseClicks,但有了幫助,當SL4出來時我得到了這個工作。現在我轉移到一臺新機器上,下載了RX,並且我知道RX經歷了一些破壞此代碼的更改。我試過了,但我似乎無法從FastSubject中轉換過渡。Rx突然變化

我真的很想在這裏完全理解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 
     }); 

回答

2

FastSubject只是主題現在,所有主題都快:)但是,這是一個奇怪的方式來檢查雙擊。

如何只(警告:通過文本區域編碼):

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]);