Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Smarter rendering in v2 #1466

Draft
wants to merge 1 commit into
base: v2
Choose a base branch
from
Draft

Smarter rendering in v2 #1466

wants to merge 1 commit into from

Conversation

egil
Copy link
Member

@egil egil commented May 10, 2024

With v2, IRenderedComponent<TComponent> is inherting from ComponentState.

A component can:

  • Be disposed
  • Have disposed event handlers
  • Have changes or be updated

During/after each render cycle (UpdateDisplayAsync):

  • Update renderer's RenderCount
  • Increment the IRenderedComponent.RenderCount IFF RenderTreeDiff.Edits.Count > 0
  • Component has been updated, has disposed event handlers, or been disposed, notify subscribers (wait-fors).
  • If any component has RenderTreeDiff.Edits.Count > 0, tell ROOT to recreate markup.
    • Track start and end indices for each component.
    • Create or update/patch a single DOM tree
    • Provide a way for each rendered component to return just the nodes they own.

DOM tree


NOTES and example below:

IRenderedComponent<BunitRootComponent> cut = Render(....);
IRenderedComponent<FooButton> button = cut.FindComponent<FooButton>();
button.Markup // slice of the cut.Markup
button.Nodes // 

// Go from component (tree) to element
var buttonElementFromRoot = cut.Find("button");
var buttonElementFromFooButton = button.Find("button");

// Reuse of AngleSharp DOM nodes across rendered components
ReferenceEquals(buttonElementFromRoot, buttonElementFromFooButton);

// Go from element to component tree
IRenderedComponent<FooButton> comp = buttonElementFromFooButton.GetComponent<FooButton>();

// Should be able to see node changes without re-finding for them.
button.Click();
buttonElementFromRoot.InnerText.Should().Be("Counter: 1");

component: 4 ... 20
node:

  • text
    element: 6 .. 18

@linkdotnet linkdotnet force-pushed the feat/v2-smarter-rendering branch from da0fc7a to ec1a275 Compare July 21, 2024 19:21
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant