Skip to content

Commit cfdff41

Browse files
committed
small change to not dirty atoms that are the same
1 parent bac641a commit cfdff41

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

tsunami/frontend/src/model/tsunami-model.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import debug from "debug";
55
import * as jotai from "jotai";
66

77
import { getOrCreateClientId } from "@/util/clientid";
8-
import { adaptFromReactOrNativeKeyEvent, checkKeyPressed } from "@/util/keyutil";
8+
import { adaptFromReactOrNativeKeyEvent } from "@/util/keyutil";
99
import { PLATFORM, PlatformMacOS } from "@/util/platformutil";
1010
import { getDefaultStore } from "jotai";
1111
import { applyCanvasOp, restoreVDomElems } from "./model-utils";
@@ -473,6 +473,9 @@ export class TsunamiModel {
473473
setAtomValue(atomName: string, value: any, fromBe: boolean, idMap: Map<string, VDomElem>) {
474474
dlog("setAtomValue", atomName, value, fromBe);
475475
let container = this.getAtomContainer(atomName);
476+
if (container.val === value) {
477+
return;
478+
}
476479
container.val = value;
477480
if (fromBe) {
478481
container.beVal = value;
@@ -533,17 +536,17 @@ export class TsunamiModel {
533536
if (faviconPath === this.cachedFaviconPath) {
534537
return;
535538
}
536-
539+
537540
this.cachedFaviconPath = faviconPath;
538-
541+
539542
let existingFavicon = document.querySelector('link[rel="icon"]') as HTMLLinkElement;
540-
543+
541544
if (faviconPath) {
542545
if (existingFavicon) {
543546
existingFavicon.href = faviconPath;
544547
} else {
545-
const link = document.createElement('link');
546-
link.rel = 'icon';
548+
const link = document.createElement("link");
549+
link.rel = "icon";
547550
link.href = faviconPath;
548551
document.head.appendChild(link);
549552
}
@@ -558,7 +561,7 @@ export class TsunamiModel {
558561
if (update == null) {
559562
return;
560563
}
561-
564+
562565
// Check if serverId is changing and trigger remount if needed
563566
if (this.serverId != null && this.serverId !== update.serverid) {
564567
// Server ID changed - need to remount the entire app
@@ -567,7 +570,7 @@ export class TsunamiModel {
567570
}
568571
return;
569572
}
570-
573+
571574
this.serverId = update.serverid;
572575
getDefaultStore().set(this.contextActive, true);
573576
const idMap = new Map<string, VDomElem>();

tsunami/frontend/src/vdom.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import * as React from "react";
99
import { Markdown } from "@/element/markdown";
1010
import { getTextChildren } from "@/model/model-utils";
1111
import type { TsunamiModel } from "@/model/tsunami-model";
12-
import { adaptFromReactOrNativeKeyEvent, checkKeyPressed } from "@/util/keyutil";
1312
import { RechartsTag } from "@/recharts/recharts";
13+
import { adaptFromReactOrNativeKeyEvent, checkKeyPressed } from "@/util/keyutil";
1414

1515
const TextTag = "#text";
1616
const FragmentTag = "#fragment";
@@ -332,12 +332,12 @@ function VDomTag({ elem, model }: { elem: VDomElem; model: TsunamiModel }) {
332332
if (elem.tag == WaveTextTag) {
333333
return props.text;
334334
}
335-
335+
336336
// Dispatch recharts: prefixed tags to RechartsTag
337337
if (elem.tag.startsWith("recharts:")) {
338338
return <RechartsTag elem={elem} model={model} />;
339339
}
340-
340+
341341
const waveTag = WaveTagMap[elem.tag];
342342
if (waveTag) {
343343
return waveTag({ elem, model });

0 commit comments

Comments
 (0)