-
-
Notifications
You must be signed in to change notification settings - Fork 264
Add brouter to bit Boilerplate (#12687) #12688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,9 @@ | |
| { | ||
| "id": "ads" | ||
| }, | ||
| { | ||
| "id": "brouter" | ||
| }, | ||
| { | ||
| "id": "apiServerUrl", | ||
| "isVisible": false | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| namespace Boilerplate.Client.Core.Components.Pages; | ||
|
|
||
| /// <summary> | ||
| /// bit Brouter route-lifecycle hooks for pages deriving from <see cref="AppPageBase"/>. | ||
| /// | ||
| /// <para> | ||
| /// Brouter treats routing as more than "match a URL and mount a component". A route can be marked | ||
| /// <c>KeepAlive</c> (see <c>Routes.razor</c>): instead of being torn down when you navigate away, the | ||
| /// page's component instance is retained and merely <em>hidden</em>, then <em>revealed</em> again on | ||
| /// return - so scroll position, grid paging/sorting/filtering, unsaved input, in-flight state, etc. all | ||
| /// survive the round-trip. And whether a page is kept alive or not, Brouter gives it a much richer | ||
| /// lifecycle than Blazor's bare <c>OnInitialized</c>/<c>Dispose</c> pair. | ||
| /// </para> | ||
| /// </summary> | ||
| public abstract partial class AppPageBase : IBrouterRoute | ||
|
Check failure on line 15 in src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/AppPageBase.BrouterLifecycles.cs
|
||
| { | ||
| /// <summary> | ||
| /// <inheritdoc cref="IBrouterRoute.OnActivatedAsync"/> | ||
| /// </summary> | ||
| protected virtual async ValueTask OnActivated(BrouterRouteActivation activation) { } | ||
|
Check failure on line 20 in src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/AppPageBase.BrouterLifecycles.cs
|
||
| public async ValueTask OnActivatedAsync(BrouterRouteActivation activation) | ||
|
Check failure on line 21 in src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/AppPageBase.BrouterLifecycles.cs
|
||
| { | ||
| try | ||
| { | ||
| await OnActivated(activation); | ||
| } | ||
| catch (Exception exp) | ||
| { | ||
| ExceptionHandler.Handle(exp); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc cref="IBrouterRoute.OnDeactivatedAsync"/> | ||
| /// </summary> | ||
| protected virtual async ValueTask OnDeactivated(BrouterRouteDeactivation deactivation) { } | ||
|
Check failure on line 36 in src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/AppPageBase.BrouterLifecycles.cs
|
||
| public async ValueTask OnDeactivatedAsync(BrouterRouteDeactivation deactivation) | ||
|
Check failure on line 37 in src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/AppPageBase.BrouterLifecycles.cs
|
||
| { | ||
| try | ||
| { | ||
| await OnDeactivated(deactivation); | ||
| } | ||
| catch (Exception exp) | ||
| { | ||
| ExceptionHandler.Handle(exp); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc cref="IBrouterRoute.OnDeactivatingAsync"/> | ||
| /// </summary> | ||
| protected virtual async ValueTask OnDeactivating(BrouterRouteDeactivatingContext context) { } | ||
|
Check failure on line 52 in src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/AppPageBase.BrouterLifecycles.cs
|
||
| public async ValueTask OnDeactivatingAsync(BrouterRouteDeactivatingContext context) | ||
| { | ||
| try | ||
| { | ||
| await OnDeactivating(context); | ||
| } | ||
| catch (Exception exp) | ||
| { | ||
| ExceptionHandler.Handle(exp); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc cref="IBrouterRoute.OnRenavigatedAsync"/> | ||
| /// </summary> | ||
| protected virtual async ValueTask OnRenavigated(BrouterRouteRenavigation renavigation) { } | ||
| public async ValueTask OnRenavigatedAsync(BrouterRouteRenavigation renavigation) | ||
| { | ||
| try | ||
| { | ||
| await OnRenavigated(renavigation); | ||
| } | ||
| catch (Exception exp) | ||
| { | ||
| ExceptionHandler.Handle(exp); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc cref="IBrouterRoute.OnRenavigatingAsync"/> | ||
| /// </summary> | ||
| protected virtual async ValueTask OnRenavigating(BrouterRouteRenavigatingContext context) { } | ||
| public async ValueTask OnRenavigatingAsync(BrouterRouteRenavigatingContext context) | ||
| { | ||
| try | ||
| { | ||
| await OnRenavigating(context); | ||
| } | ||
| catch (Exception exp) | ||
| { | ||
| ExceptionHandler.Handle(exp); | ||
| } | ||
| } | ||
|
|
||
| // The following code enables Brouter route-lifecycle hooks for pages inheriting from AppPageBase. | ||
|
|
||
| [CascadingParameter] private BrouterRouteContext? routeContext { get; set; } | ||
| private bool brouterRegistered; | ||
|
|
||
| public override Task SetParametersAsync(ParameterView parameters) | ||
| { | ||
| var task = base.SetParametersAsync(parameters); | ||
|
|
||
| if (brouterRegistered is false && routeContext is not null) | ||
| { | ||
| routeContext.Register(this); | ||
| brouterRegistered = true; | ||
| } | ||
|
|
||
| return task; | ||
| } | ||
|
|
||
| protected override ValueTask DisposeAsync(bool disposing) | ||
| { | ||
| if (brouterRegistered) | ||
| { | ||
| routeContext?.Unregister(this); | ||
| brouterRegistered = false; | ||
| } | ||
|
|
||
| return base.DisposeAsync(disposing); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.