Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ReactiveUI Tablet Solutions

ReactiveUI Tablet Solutions

Avatar for Dennis Daume

Dennis Daume

May 31, 2016

Other Decks in Programming

Transcript

  1. ReactiveUI Akavache Refit Splat MahApps.Metro Open Source © Tablet Solutions

    GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI” Dennis Daume @flagbug About me
  2. WPF WinForms WinRT Windows Phone © Tablet Solutions GmbH, Dennis

    Daume - “Building Reactive Mobile Apps with ReactiveUI” Xamarin.Android Xamarin.iOS Xamarin.Mac Platforms
  3. Who’s using ReactiveUI? Github Slack Tablet Solutions © Tablet Solutions

    GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  4. ReactiveObject ViewModel Base Implements INotifyPropertyChanged Exposes RaiseAndSetIfChanged Exposes WhenAnyValue ©

    Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  5. RaiseAndSetIfChanged Standard MVVM public string Username { get { return

    username; } set { if (username != value) { username = value; } this.OnPropertyChanged(); } } ReactiveUI public string Username { get { return this.username; } set { this.RaiseAndSetIfChanged( ref this.username, value); } } © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  6. RaiseAndSetIfChanged public string Username { get { return this.username; }

    set { this.RaiseAndSetIfChanged(this.username, value); } } public string Password { get { return this.username; } set { this.RaiseAndSetIfChanged(this.username, value); } } © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  7. this.WhenAnyValue this.WhenAnyValue(x => x.Username, x => x.Password, (username, password) =>

    !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password)) .Subscribe(canLogin => /* Enable/Disable Login Button */ ); © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  8. Combining Values public int Red { get { return this.red;

    } set { this.RaiseAndSetIfChanged(ref this.red, value); } } public int Green { get { return this.green; } set { this.RaiseAndSetIfChanged(ref this.green, value); } } public int Blue { get { return this.red; } set { this.RaiseAndSetIfChanged(ref this.blue, value); } } © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  9. private ObservableAsPropertyHelper<Color> color; public Color Color => this.color.Value; // In

    the constructor this.WhenAnyValue(x => x.Red, x => x.Green, x => x.Blue, (r, g, b) => new Color(r, g, b)) .ToProperty(this, x => x.Color, out this.color); ToProperty © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  10. this.WhenAnyValue(x => x.SearchTerm) .Where(s => !String.IsNullOrEmpty(s)) .Throttle(TimeSpan.FromSeconds(0.5)) .Select(s => DoSearch(s).Retry(3))

    .Catch(Observable.Return(Enumerable.Empty<Result>())) .Switch() .ToProperty(this, x => x.ListOfSearchResults); © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  11. Commanding ICommand • bool CanExecute(object o) • void Execute(object o)

    ReactiveCommand • IObservable<bool> CanExecute { get; } • Task<T> ExecuteAsyncTask(object o); © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  12. ReactiveCommand var canLogin = this.WhenAnyValue(x => x.Username, x => x.Password,

    (username, password) => !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password)); this.LoginCommand = ReactiveCommand.CreateAsyncTask(canLogin, _ => /* Send login request to server */ ); <Button Content=“Login” Command=“{Binding LoginCommand}” /> © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  13. ReactiveCommand Notifies UI of CanExecute change Asynchronous Testable © Tablet

    Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  14. var viewModel = new LoginViewModel(); await viewModel.Login.ExecuteAsyncTask(); // assert something

    © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”
  15. What else? Cross-Platform Bindings Reactive Collections Error Handling Routing Activation

    © Tablet Solutions GmbH, Dennis Daume - “Building Reactive Mobile Apps with ReactiveUI”