Exemple #1
0
        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);
                }
            });
        }
Exemple #2
0
 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 default view model for the router.
 /// </summary>
 /// <param name="router">The router.</param>
 /// <returns>Returns a task that represents the async operation.</returns>
 public static Task ShowDefaultViewModelAsync(this IRouter router)
 {
     return(router.DispatchAsync(RouterActions.ShowDefaultViewModel()));
 }
 /// <summary>
 /// Navigates backwards toward the previous view model.
 /// </summary>
 /// <param name="router">The router.</param>
 /// <param name="closeAppIfNeeded">
 /// Whether the application should be closed if navigating back from the root view model.
 /// Only applicable on devices that have OS-integrated back buttons.
 /// </param>
 /// <returns>Returns a task that represents the async operation.</returns>
 public static Task BackAsync(this IRouter router, bool closeAppIfNeeded = true)
 {
     return(router.DispatchAsync(RouterActions.Back(closeAppIfNeeded)));
 }
 /// <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)));
 }