hydrostack/hydro

Support dynamic component generation

kjeske opened this issue · 0 comments

Make it possible to automatically produce a Hydro component when an event occurs.

Example:

public Task AddPost()
{
    var post = new Post();
    database.Add(post);
    await database.SaveChanges();

    DispatchGlobal(new PostCreated(PostId: post.Id));
}
public class Post : HydroComponent
{
    public Guid PostId { get; set; }
}
<hydro name="Post" generate-on="typeof(PostCreated)" />

When AddPost action is triggered, it dispatches PostCreated event, which causes a new instance of Post component to render (thanks to generate-on) with the properties taken from the event (PostId).