|
1 | | -using Sylac.Mvvm.Navigation.Abstractions; |
| 1 | +using Sylac.Mvvm.Abstraction; |
| 2 | +using Sylac.Mvvm.Navigation.Abstractions; |
2 | 3 | using System.Reactive; |
3 | 4 | using System.Reactive.Linq; |
4 | 5 |
|
5 | 6 | namespace Sylac.Mvvm.Navigation; |
6 | 7 |
|
7 | | -public class NavigationService(IPlatformNavigation platformNavigation) : INavigationService |
| 8 | +public sealed class NavigationService(IPlatformNavigation platformNavigation) : INavigationService |
8 | 9 | { |
9 | 10 | private readonly IPlatformNavigation _platformNavigation = platformNavigation; |
10 | 11 | internal static Dictionary<Type, (string Page, Type ParametersType)> ViewModelsRegistry { get; } = []; |
@@ -41,33 +42,18 @@ public IObservable<Unit> NavigateTo<TViewModel, TParams>(TParams parameters) |
41 | 42 | where TParams : IViewModelParameters |
42 | 43 | { |
43 | 44 | return Observable.Return(ViewModelsRegistry.GetValueOrDefault(typeof(TViewModel))) |
44 | | - .Where(result => |
45 | | - result.Page != default && |
46 | | - result.ParametersType != default) |
| 45 | + .Where(result => result != default) |
47 | 46 | .SelectMany(result => |
48 | | - { |
49 | 47 | // is type check needed? Is it possible to pass a different type? |
50 | | - if (parameters.GetType() != result.ParametersType) |
51 | | - { |
52 | | - return Observable.Throw<Unit>(new ArgumentException("Invalid parameters type")); |
53 | | - } |
54 | | - |
55 | | - return _platformNavigation.GoTo(result.Page, new Dictionary<string, object>() { { INavigationablePage.ParametersKey, parameters } }); |
56 | | - }) |
| 48 | + parameters.GetType() != result.ParametersType |
| 49 | + ? Observable.Throw<Unit>(new ArgumentException("Invalid parameters type")) |
| 50 | + : _platformNavigation.GoTo(result.Page, new Dictionary<string, object>() { { INavigationablePage.ParametersKey, parameters } })) |
57 | 51 | .IsEmpty() |
58 | | - .SelectMany(isEmpty => |
59 | | - { |
60 | | - if (isEmpty) |
61 | | - { |
62 | | - return Observable.Throw<Unit>(new ArgumentException("Error navigating to page")); |
63 | | - } |
64 | | - return Observable.Return(Unit.Default); |
65 | | - }); |
| 52 | + .SelectMany(isEmpty => isEmpty |
| 53 | + ? Observable.Throw<Unit>(new ArgumentException("Error navigating to page")) |
| 54 | + : Observable.Return(Unit.Default)); |
66 | 55 | } |
67 | 56 |
|
68 | | - public IObservable<Unit> NavigateBack() |
69 | | - { |
70 | | - return _platformNavigation.GoTo(".."); |
71 | | - } |
| 57 | + public IObservable<Unit> NavigateBack() => _platformNavigation.GoTo(".."); |
72 | 58 | } |
73 | 59 |
|
0 commit comments