ReactiveUI 5.x changes

I’m not sure when these changes were made, but I just updated an application to use both .NET 4.5 and the latest NuGet packages for ReactiveUI (version 5.4) and looks like quite a few things have changed.

This post is just going to show some of the changes I’ve hit whilst migrating my code. This is probably not a full list as I haven’t used all the parts of ReactiveUI in my applications thus far.

RaiseAndSetIfChanged

// old style
this.RaiseAndSetIfChanged(x => x.IsSelected, ref isSelected, value);

// new style
this.RaiseAndSetIfChanged(ref isSelected, value);

See the post on CallerMemberNameAttribute for more information on how this works. With this we no longer need to write the lambda expressions required by earlier versions.

Note: For raising events on properties other than the current property, i.e. if IsSelected is a property above and IsUpdated should also raise a property change event we use

this.RaiseAndSetIfChanged("IsUpdated");


RxApp.DeferredScheduler

It would appear that the RxApp.DeferredScheduler has been renamed as RxApp.MainThreaScheduler. Admittedly a better name.

RxApp.MessageBus

Looks like we just use the MessageBux.Current instead.

ReactiveAsyncCommand

It appears that ReactiveAsyncCommand has merged into ReactiveCommand, so changes look like this

// old stype
ClearSearch = new ReactiveAsyncCommand(null);
ClearSearch.RegisterAsyncAction(o =>
{
   // do something
});

// new style
ClearSearch = new ReactiveCommand();
ClearSearch.RegisterAsyncAction(o =>
{
   // do something
});

but there’s more

// old style
OK = ReactiveCommand.Create(_ => true, DoOK);

// new style
OK = new ReactiveCommand();
OK.Subscribe(DoOK);

If we need to enable/disable commands then we can pass an IObservable into the first parameter of ReactiveCommand, for example

OK = new ReactiveCommand(this.WhenAny(x => x.Text, x => !String.IsNullOrEmpty(x.Value)));


IReactiveAsyncCommand

As above, IReactiveAsyncCommand has been merged into IReactiveCommand.

ReactiveCollection

This has been renamed to ReactiveList.