Skip to content

Commit

Permalink
housekeeping: Added Error Interactions to Sextant Sample (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
RLittlesII authored Jun 12, 2019
1 parent 9d3069a commit 77494ec
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Sample/SextantSample/Interactions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using ReactiveUI;

namespace SextantSample
{
public static class Interactions
{
public static Interaction<Exception, bool> ErrorMessage = new Interaction<Exception, bool>();
}
}
4 changes: 2 additions & 2 deletions Sample/SextantSample/ViewModels/FirstModalViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public FirstModalViewModel(IViewStackService viewStackService) : base(viewStackS

OpenModal.Subscribe(x => Debug.WriteLine("PagePushed"));
PopModal.Subscribe(x => Debug.WriteLine("PagePoped"));

}
PopModal.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
}
}
}
3 changes: 3 additions & 0 deletions Sample/SextantSample/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public HomeViewModel()
outputScheduler: RxApp.MainThreadScheduler);

OpenModal.Subscribe(x => Debug.WriteLine("PagePushed"));

PushPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
OpenModal.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
}
}
}
6 changes: 5 additions & 1 deletion Sample/SextantSample/ViewModels/RedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public RedViewModel(IViewStackService viewStackService) : base(viewStackService)
outputScheduler: RxApp.MainThreadScheduler);

PopModal.Subscribe(x => Debug.WriteLine("PagePushed"));
}
PopModal.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
PopPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
PushPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
PopToRoot.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
}
}
}
5 changes: 4 additions & 1 deletion Sample/SextantSample/ViewModels/SecondModalViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Diagnostics;
using Sextant;
using System.Reactive.Linq;

namespace SextantSample.ViewModels
{
Expand Down Expand Up @@ -37,6 +38,8 @@ public SecondModalViewModel(IViewStackService viewStackService) : base(viewStack
PushPage.Subscribe(x => Debug.WriteLine("PagePushed"));
PopModal.Subscribe(x => Debug.WriteLine("PagePoped"));

}
PushPage.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
PopModal.ThrownExceptions.Subscribe(error => Interactions.ErrorMessage.Handle(error).Subscribe());
}
}
}
8 changes: 8 additions & 0 deletions Sample/SextantSample/Views/FirstModalView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public FirstModalView()
InitializeComponent();
this.BindCommand(ViewModel, x => x.OpenModal, x => x.OpenSecondModal);
this.BindCommand(ViewModel, x => x.PopModal, x => x.PopModal);

Interactions
.ErrorMessage
.RegisterHandler(async x =>
{
await DisplayAlert("Error", x.Input.Message, "Done");
x.SetOutput(true);
});
}
}
}
8 changes: 8 additions & 0 deletions Sample/SextantSample/Views/HomeView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public HomeView()
this.BindCommand(ViewModel, x => x.OpenModal, x => x.FirstModalButton).DisposeWith(disposables);
this.BindCommand(ViewModel, x => x.PushPage, x => x.PushPage);
});

Interactions
.ErrorMessage
.RegisterHandler(async x =>
{
await DisplayAlert("Error", x.Input.Message, "Done");
x.SetOutput(true);
});
}
}
}
8 changes: 8 additions & 0 deletions Sample/SextantSample/Views/RedView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public RedView()
this.BindCommand(ViewModel, x => x.PushPage, x => x.PushPage);
this.BindCommand(ViewModel, x => x.PopPage, x => x.PopPage);
this.BindCommand(ViewModel, x => x.PopToRoot, x => x.PopToRoot);

Interactions
.ErrorMessage
.RegisterHandler(async x =>
{
await DisplayAlert("Error", x.Input.Message, "Done");
x.SetOutput(true);
});
}
}
}
8 changes: 8 additions & 0 deletions Sample/SextantSample/Views/SecondModalView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public SecondModalView()
InitializeComponent();
this.BindCommand(ViewModel, x => x.PushPage, x => x.PushPage);
this.BindCommand(ViewModel, x => x.PopModal, x => x.PopModal);

Interactions
.ErrorMessage
.RegisterHandler(async x =>
{
await DisplayAlert("Error", x.Input.Message, "Done");
x.SetOutput(true);
});
}
}
}

0 comments on commit 77494ec

Please sign in to comment.