system.reactive

Convert Polling Web Service to RX

空扰寡人 提交于 2019-12-06 12:24:30
Given: public partial class Weather { private readonly DispatcherTimer _timer = new DispatcherTimer(); private readonly IWeatherDataProvider _weatherDataProvider; public Weather(IWeatherDataProvider weatherDataProvider) { InitializeComponent(); _weatherDataProvider = weatherDataProvider; Loaded += async (sender, args) => { _timer.Interval = new TimeSpan(0, 15, 0); _timer.Tick += async (o, eventArgs) => DataContext = await UpdateWeather(); _timer.Start(); DataContext = await UpdateWeather(); }; Unloaded += (sender, args) => _timer.Stop(); } private async Task<WeatherData> UpdateWeather() { var

Correct way to merge observable sequences for events fired from multiple instances

无人久伴 提交于 2019-12-06 12:23:39
Say I have a factory method that churns out instances of type T, and I want an Rx observable sequence for events fired from all my instances originating out of the factory method. Is using Merge() as I have done below the correct and optimal way to achieve this? The other way I did this was to use a static event and make the observable sequence out of that, however I generally don't like using static events and am curious what any Rx experts think would be optimal in this situation? public T MakeFoo<T>() where T: Foo, new() { this.instanceOfObservable.Merge(new T()); return self; } public

Rx: Ignoring updates caused by Subscribers

点点圈 提交于 2019-12-06 11:36:29
I'm having problems figuring out how to do this. I have two instances (source & target) that implement INotifyPropertyChanged and I'm tracking the PropertyChanged event for both. What I want to do is run an action any time source.PropertyChanged is raised until target.PropertyChanged is raised. I can do that just fine like this: INotifyPropertyChanged source; INotifyPropertyChanged target; var sourcePropertyChanged = Observable .FromEvent<PropertyChangedEventArgs>(source, "PropertyChanged") .Where(x => x.EventArgs.PropertyName == sourcePropertyName); var targetPropertyChanged = Observable

How do I merge several observables using WhenAny(…) in ReactiveUI?

泄露秘密 提交于 2019-12-06 08:29:15
问题 I have a question which is an extension of the following question raised on this site. Is there a more elegant way to merge observables when return type is unimportant? I have an IObservable<Unit> (lets say X ), a reactive collection ( Y ) and a property ( Z ). Return type is not important. I just want to subscribe when any of these change. I know how to observe all 3 and Subscribe using Observable.Merge as below. Observable.Merge(X, Y.Changed, ObservableForProperty(Z).Select(_ => Unit

Data service in Reactive Extension

杀马特。学长 韩版系。学妹 提交于 2019-12-06 08:11:18
问题 I want to have a generic class for an in-memory cache of data handling creations, updates and deletions. Underlying model inherits from an interface with an Id of type string. interface IModel { string Id { get; } } Handling creations & updates is easy. For instance, if I want to subscribe to the stream and populate a Dictionary, I know that a creation is needed if the model Id is not already there, otherwise it is an update. My question is: How would you handle deletions without introducing

Is it possible to invoke subscribers's OnNexts on different threads in Rx?

梦想的初衷 提交于 2019-12-06 07:27:52
问题 I am new to Rx. I want to know if it is possible to dispatch a message to different subscribers such that they run on different thread? How can an IObserable control it? The plain Subject implementation, as I understand it calls the subscribers one after the other on a single thread. public class Subsciber : IObserver<int> { public void OnNext(int a) { // Do something } public void OnError(Exception e) { // Do something } public void OnCompeleted() { } } public static class Program { public

detecting multitouch longpress event using rxjs

旧街凉风 提交于 2019-12-06 07:12:21
问题 Been playing around with rxjs. I find it really good, but it really took some time to get my head around it. Here's a little one I can't solve, so I'm looking for some insight. Consider a multitouch interface where for each touchstart/touchmove/touchend you would have as params an object with {id:, x:x, y:y, t:t, current_pointers: } I would like an observable that would trigger an event for each down pointer after 1500 ms unless touchmove or touchup happens for that pointer. For a single

how to do Rx Observable on Silverlight Webclient

北慕城南 提交于 2019-12-06 07:02:00
问题 I would like to use Rx in my SL app. I want to set up an observable on my REST requests to my webserver. I dont see how to wire up Observable.FromEvent or Observable.FromAsync. My best guess is to make Webclient completion fire an event and then do Observable.FromEvent. IS there a better way? 回答1: Here you go, this is the best way to make a web request in Rx. public IObservable<WebResponse> MakeWebRequest( Uri uri, Dictionary<string, string> headers = null, string content = null, int retries

Observe PropertyChanged on items in an ObservableCollection using System.Reactive

只愿长相守 提交于 2019-12-06 05:26:40
I have: public class Vm { private ObservableCollection<Thing> _things; public ObservableCollection<Thing> Things { get { return _things ?? (_things = new ObservableCollection<Thing>()); } } } And public class Thing :INotifyPropertyChanged { private string _value; public string Value { get { return _value; } set { if (value == _value) return; _value = value; OnPropertyChanged(); } } public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChangedEventHandler

Between values with Rx

主宰稳场 提交于 2019-12-06 05:15:13
Is there some extension method in Rx to do the scenario below? I have a value to start the pumping (green circles) and other value to stop the pumping (reed circles), the blue circles should be the expected values, I would not want this command to be canceled and recreated (ie "TakeUntil" and "SkipUntil" will not work). The implementation using LINQ would be something like this: public static IEnumerable<T> TakeBetween<T>(this IEnumerable<T> source, Func<T, bool> entry, Func<T, bool> exit) { bool yield = false; foreach (var item in source) { if (!yield) { if (!entry(item)) continue; yield =