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
1 2 3 4 5 | // 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
1 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 | // 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
1 2 3 4 5 6 | // 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
1 | 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.