private async Task DispatchAsync(StoredRouterAction action) { // TODO: Cleanup to represent unidirectional dataflow // Rework to manipulate state through reducers and then // present based on the current state. await When <ShowViewModelAction>(action.Action, async showViewModelAction => { await ShowViewModelAsync(showViewModelAction, action.ViewModelState); }); await When <NavigateBackAction>(action.Action, async navigateBackAction => { await NavigateBackAsync(navigateBackAction); }); await When <ShowDefaultViewModelAction>(action.Action, async a => { if (Actions.Count == 0 && InitParams?.DefaultViewModelType != null && InitParams.DefaultParameters != null) { var stored = new StoredRouterAction() { Action = RouterActions.ShowViewModel(InitParams.DefaultViewModelType, InitParams.DefaultParameters), ViewModelState = action.ViewModelState }; await DispatchAsync(stored); } }); }
public async Task DispatchAsync(IRouterAction action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } CheckInit(); await When <ShowViewModelAction>(action, async showViewModelAction => { await ShowViewModelAsync(showViewModelAction); }); await When <NavigateBackAction>(action, async navigateBackAction => { await NavigateBackAsync(navigateBackAction); }); await When <ShowDefaultViewModelAction>(action, async a => { if (Actions.Count == 0 && InitParams?.DefaultViewModelType != null && InitParams.DefaultParameters != null) { await DispatchAsync(RouterActions.ShowViewModel(InitParams.DefaultViewModelType, InitParams.DefaultParameters)); } }); }
/// <summary> /// Routes to the given view model type, using the given parameters. /// </summary> /// <param name="router">The router.</param> /// <param name="viewModel">The type of the view model that should be routed to.</param> /// <param name="parameters">The parameters that should be passed to the view model.</param> /// <returns>Returns a task that represents the async operation.</returns> public static Task ShowAsync(this IRouter router, Type viewModel, object parameters) { return(router.DispatchAsync(RouterActions.ShowViewModel(viewModel, parameters))); }