adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
555 stars 46 forks source link

Experiment memory allocation #186

Closed adospace closed 6 months ago

adospace commented 6 months ago

Add a new component declaration pattern that pools MauiReactor objects to reduce memory allocations, it could be useful in ReenderItem methods in collection views.

Instead of:

public override VisualNode Render()
  {
      return new ContentPage("Counter Sample")
      {
          new VStack(spacing: 10)
          {
              new Label($"Counter: {State.Counter}")
                  .VCenter()
                  .HCenter(),

              new Button("Click To Increment", () =>
                  SetState(s => s.Counter++))
          }
          .VCenter()
          .HCenter()
      };
  }

this:

public override VisualNode Render()
{
    return ContentPage(
    [
        VStack(
        [
            Label($"Counter: {State.Counter}")
                .VCenter()
                .HCenter(),

            Button("Click To Increment", () =>
                SetState(s => s.Counter++))
        ])
        .Spacing(10)
        .VCenter()
        .HCenter()
    ])
    .Title("Counter Sample");
}