Skip to content

Commit

Permalink
remove unnecessary update requests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewedstrom committed Nov 21, 2023
1 parent e1aaacb commit cce4e27
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/widget/src/docmaps-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ export class DocmapsWidget extends LitElement {
@property({ type: String })
serverUrl: string = '';

@state()
@state() // if the selectedNode changes, this means we trigger a rerender (to show the details view)
selectedNode?: DisplayObject;

@state()
allNodes: DisplayObject[] = [];

#docmapFetchingTask: Task<DocmapFetchingParams, DisplayObjectGraph> = new Task(
Expand Down Expand Up @@ -64,16 +63,15 @@ export class DocmapsWidget extends LitElement {
private renderGraphView({ nodes, edges }: DisplayObjectGraph) {
if (this.shadowRoot) {
this.allNodes = nodes;
displayGraph(nodes, edges, this.shadowRoot, this.displayNodeDetails);
displayGraph(nodes, edges, this.shadowRoot, this.displayDetailsViewForNode);
}

// D3 draws the graph for us, so we have nothing to actually render here
return nothing;
}

private displayNodeDetails = (node: DisplayObject) => {
private displayDetailsViewForNode = (node: DisplayObject) => {
this.selectedNode = node;
this.requestUpdate(); // Trigger re-render
};

private renderDetailsView(selectedNode: DisplayObject): HTMLTemplateResult {
Expand All @@ -91,7 +89,7 @@ export class DocmapsWidget extends LitElement {

return html`
<div class="detail-timeline">
${renderDetailNavigationHeader(this.allNodes, selectedNode, this.displayNodeDetails)}
${renderDetailNavigationHeader(this.allNodes, selectedNode, this.displayDetailsViewForNode)}
</div>
<div class="detail-header" style="background: ${backgroundColor};">
Expand All @@ -108,7 +106,6 @@ export class DocmapsWidget extends LitElement {
// Method to clear the selected node and go back to the graph
private closeDetailsView() {
this.selectedNode = undefined;
this.requestUpdate(); // Trigger re-render
}

private createMetadataGrid(metadataEntries: [string, any][]): HTMLTemplateResult {
Expand Down

0 comments on commit cce4e27

Please sign in to comment.