namespace Sandbox.UI;
///
/// This is a tree renderer for panels. If we ever use razor on other ui we'll want to make a copy of
/// this class and do the specific things to that.
///
public partial class PanelRenderTreeBuilder : Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder
{
///
/// Handles @onclick=@( () => DoSomething( "boobies" ) )
///
public void AddAttributeAction( int sequence, string attrName, Action value )
{
// There's no real good way to cache this shit. The function is a local function, the captured variables could change at any time.
// The cost here is removing and adding to a list. We could find a way to make that less impactful. But lets wait until
// it is impactful.
//Log.Info( $"AddEventListener {attrName}" );
CurrentScope.Element.RemoveEventListener( attrName );
CurrentScope.Element.AddEventListener( attrName, value );
}
///
/// Handles @onclick=@( () => await DoSomethingAsync( "boobies" ) )
///
public void AddAttributeAction( int sequence, string attrName, Func value )
{
var e = CurrentScope.Element;
AddAttributeAction( sequence, attrName, () => { _ = value(); e?.StateHasChanged(); } );
}
///
/// Handles @onclick=@( ( PanelEvent e ) => DoSomething( e.This, "boobies" ) )
///
internal void AddPanelEventAttribute( int sequence, string attrName, Action value )
{
// There's no real good way to cache this shit. The function is a local function, the captured variables could change at any time.
// The cost here is removing and adding to a list. We could find a way to make that less impactful. But lets wait until
// it is impactful.
//Log.Info( $"AddEventListener {attrName}" );
CurrentScope.Element.RemoveEventListener( attrName );
CurrentScope.Element.AddEventListener( attrName, value );
}
}