2011-10-11 4 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]);