-
Notifications
You must be signed in to change notification settings - Fork 19
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
Await for OnInitializedAsync completes #32
Comments
I've a PR almost ready but I would like to discuss it with you a bit first, the solution was quite easy but it produces some code duplication, that could be avoided but it is required to choose which coding style to take here |
Duplicate of #23 though I don't agree with the workaround presented there and would like a proper solution as well. |
Sorry I've not noticed the #23 and the related #30 PR untill i've pushed my PR #33 . My fault, I'm in a big hurry in implementing a solution for my project. It doesn't looks to be a workaround but a proper use of already existing feature. |
I understand you can easily miss my PR because the corresponding issue has already been closed. protected override async Task OnInitializedAsync()
{
await Task.Delay(500);
await InvokeAsync(StateHasChanged);
await Task.Delay(500);
Text = "Async value";
await base.OnInitializedAsync();
} |
That's correct, it doesn't work because it introduces one more "NextRender" |
Thanks for the contribution! I've had the async issue and the previous PR #30 on my to-do list for a while. I'll review the contribution and if everything checks out, I'll update. |
Hello! Yes i've seen PR #30 and I prefer that solution. My fix (this PR #33) is a rushed solution because I really need it for my project, but it doesn't cover all the cases. |
Hi all, |
Hello, I've a scenario where my template receives a service via dependency injection
this service in turn performs an async operation.
the idea is to call the async operation in the OnInitializedAsync method of the page/component/template which will populate the asynchronously received data that the page will finally display once ready
I've seen that BlazorTemplater correctly invokes the OnInitializedAsync method (as well as all the other Async lifecycle method) but unfortunately the "render" phase appears to occur immediately without waiting the async methods to complete; So my data are not contained in the produced html.
Looks like there are no method to "RenderAsync" or am I wrong?
Do you have any ideas/plans on how to achieve this?
Basically what I would like to have is a RenderAsync Method that returns only when all the "Async" lifecycle methods of the component have completed and therefore provides the "final" html populated with all the values obtained from these async services.
-Of course I could invoke the service externally, obtain the values and then pass as parameter to the page, but I would prefer the other way because that allows me to reuse the template as normal page in my application (providing me to preview it to the user for example, before transforming it in a HTML string that I then transform in a PDF or I can email: preview is a cool feature!)
Any idea?
The text was updated successfully, but these errors were encountered: