-
Notifications
You must be signed in to change notification settings - Fork 10k
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
OnParametersSetAsync ? #15344
Comments
@chanan Hi, I am using it. It works as expected. Blazor 0.7 |
@michaelvolz What method signature are you using or what interface are you overriding? I only see |
@chanan I simply inherit from Blazorcomponent. The IComponent interface doesn't have the methods declared. using Microsoft.AspNetCore.Blazor.RenderTree;
using System;
using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Blazor.Components
{
/// <summary>
/// Optional base class for Blazor components. Alternatively, Blazor components may
/// implement <see cref="T:Microsoft.AspNetCore.Blazor.Components.IComponent" /> directly.
/// </summary>
public abstract class BlazorComponent : IComponent, IHandleEvent, IHandleAfterRender
{
/// <summary>
/// Constructs an instance of <see cref="T:Microsoft.AspNetCore.Blazor.Components.BlazorComponent" />.
/// </summary>
public BlazorComponent()
{
this._renderFragment = new RenderFragment(this.BuildRenderTree);
}
[...]
/// <summary>
/// Method invoked when the component is ready to start, having received its
/// initial parameters from its parent in the render tree.
/// </summary>
protected virtual void OnInit()
{
}
/// <summary>
/// Method invoked when the component is ready to start, having received its
/// initial parameters from its parent in the render tree.
///
/// Override this method if you will perform an asynchronous operation and
/// want the component to refresh when that operation is completed.
/// </summary>
/// <returns>A <see cref="T:System.Threading.Tasks.Task" /> representing any asynchronous operation.</returns>
protected virtual Task OnInitAsync()
{
return Task.CompletedTask;
}
/// <summary>
/// Method invoked when the component has received parameters from its parent in
/// the render tree, and the incoming values have been assigned to properties.
/// </summary>
protected virtual void OnParametersSet()
{
}
/// <summary>
/// Method invoked when the component has received parameters from its parent in
/// the render tree, and the incoming values have been assigned to properties.
/// </summary>
/// <returns>A <see cref="T:System.Threading.Tasks.Task" /> representing any asynchronous operation.</returns>
protected virtual Task OnParametersSetAsync()
{
return Task.CompletedTask;
}
/// <summary>
/// Method invoked after each time the component has been rendered.
/// </summary>
protected virtual void OnAfterRender()
{
}
/// <summary>
/// Method invoked after each time the component has been rendered. Note that the component does
/// not automatically re-render after the completion of any returned <see cref="T:System.Threading.Tasks.Task" />, because
/// that would cause an infinite render loop.
/// </summary>
/// <returns>A <see cref="T:System.Threading.Tasks.Task" /> representing any asynchronous operation.</returns>
protected virtual Task OnAfterRenderAsync()
{
return Task.CompletedTask;
}
/// <summary>
/// Method invoked to apply initial or updated parameters to the component.
/// </summary>
/// <param name="parameters">The parameters to apply.</param>
public virtual void SetParameters(ParameterCollection parameters)
{
parameters.AssignToProperties((object) this);
if (!this._hasCalledInit)
{
this._hasCalledInit = true;
this.OnInit();
Task task = this.OnInitAsync();
if (task != null && task.Status != TaskStatus.RanToCompletion)
task.ContinueWith(new Action<Task>(this.ContinueAfterLifecycleTask));
}
this.OnParametersSet();
Task task1 = this.OnParametersSetAsync();
if (task1 != null && task1.Status != TaskStatus.RanToCompletion)
task1.ContinueWith(new Action<Task>(this.ContinueAfterLifecycleTask));
this.StateHasChanged();
}
[...]
}
} |
Thanks @michaelvolz I will try it out! |
Sadly, while it might work (not sure yet), doesn't looks like dynamic attributes will work anymore. @SteveSandersonMS Can you suggest a solution here? If you recall, I took your code from when you started on the bootstrap components and I am using it here: https://github.com/chanan/Blazorous/blob/master/src/Blazorous/Dynamic.cs - but when I run it as inherits from BalzorComponent so that I can use OnParametersSetAsync (which doesnt seem to exist in an interface) I no longer respects attributes as being dynamic and I get the error that I need to have the [Parameter] attribute (Or maybe I would get that error either way, not sure). |
Robin Sue in the glitter.im room pointed me to https://github.com/aspnet/Blazor/issues/1659#issuecomment-437944981 which fixes my issues. |
Hi,
In issue aspnet/Blazor#1252 @danroth27 mentioned that OnParametersSetAsync will be added, but it doesnt seem to be there in the V0.7.0. Is it going to be added soon?
Thanks,
Chanan
The text was updated successfully, but these errors were encountered: