Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to ignore the initial value for a ReactiveObject?

Tags:

c#

reactiveui

Using ReactiveUI, is it possible to ignore the initial value for a given ReactiveObject?

For example, I have a ViewModel I initialize, and then I WhenAnyValue on the ViewModel. I get notified immediately that the value is null for my chosen property. Yes, I could .Where(x => x != null) to avoid this, but it's potentially possible that knowing it's null later is of value.

In other words, I want to start getting notifications after the 1st change in the value.

I'm not readily seeing how I can do this or if it's even possible. I see references to Initial Value in the source for WantsAnyValue/WantsAny but it's unclear to me how I set that initial value.

like image 493
AJ Venturella Avatar asked Apr 14 '15 20:04

AJ Venturella


2 Answers

Moving my comment to an answer on request of OP for points ;)

To ignore the first OnNext at init.

this.WhenAnyValue( model => model.Field ).Skip( 1 )
like image 112
kenny Avatar answered Nov 17 '22 03:11

kenny


You should use ObservableForProperty in this case.

WhenAnyValue will immediately notify about the initial value to the subscriber plus any new values in the future while ObservableForProperty only notifies about new values and skips the initial value.

like image 35
Tiago Avatar answered Nov 17 '22 04:11

Tiago