Skip to content

Commit

Permalink
Prevent rerendering rcc (#275)
Browse files Browse the repository at this point in the history
* overrides should render in rcc to prevent re-rendering

* adds force rendering method to rcc & re-renders when presentation or context changes
  • Loading branch information
PTKu authored Dec 20, 2023
1 parent f8eb549 commit 4da8d86
Showing 1 changed file with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,32 @@ public partial class RenderableContentControl : ComponentBase, IDisposable
public object Context
{
get => _context;
set { _context = value as ITwinElement; }
set
{
if (_context != value)
{
_context = value as ITwinElement;
this.ForceRender();
}
}
}

/// <summary>
/// Parameter Presentation specify mode, in which view UI is generated. Type PresentationType is used.
/// </summary>
[Parameter]
public string Presentation { get; set; }
public string Presentation
{
get => _presentation;
set
{
if (_presentation != value)
{
_presentation = value;
this.ForceRender();
}
}
}


/// <summary>
Expand All @@ -70,7 +88,6 @@ public object Context
/// </summary>
[Parameter]
public string LayoutChildrenClass { get; set; }

[Inject]
public ComponentService ComponentService { get; set; }
[Inject]
Expand All @@ -92,9 +109,18 @@ protected override void OnInitialized()
}
}

/// <summary>
/// Forces re-rendering of this rcc.
/// [!IMPORTANT] Forced re-rendering may impact client-side performance. The method is automatically called when <see cref="Presentation"/> or <see cref="Context"/> property change.
/// </summary>
public void ForceRender()
{
shouldRender = true;
this.StateHasChanged();
}

protected override void OnParametersSet()
{

Type layoutType = TryLoadLayoutTypeFromProperty(_context);
if (layoutType == null)
{
Expand Down Expand Up @@ -414,8 +440,17 @@ private string GetDisplayPresentationIfEmpty()

}

private bool shouldRender = false;
private string _presentation;

protected override bool ShouldRender()
{
if (shouldRender)
{
shouldRender = false;
return true;
}

return false;
}

Expand Down

0 comments on commit 4da8d86

Please sign in to comment.