diff --git a/frontend/faraday/lib/layoutAtom.ts b/frontend/faraday/lib/layoutAtom.ts index 65e74bc0b..ecd43871f 100644 --- a/frontend/faraday/lib/layoutAtom.ts +++ b/frontend/faraday/lib/layoutAtom.ts @@ -32,15 +32,17 @@ export function newLayoutTreeStateAtom(rootNode: LayoutNode): PrimitiveAto */ export function withLayoutTreeState(layoutNodeAtom: WritableLayoutNodeAtom): WritableLayoutTreeStateAtom { const pendingActionAtom = atom(null) as PrimitiveAtom; + const generationAtom = atom(0) as PrimitiveAtom; return atom( (get) => { const layoutState = newLayoutTreeState(get(layoutNodeAtom)); layoutState.pendingAction = get(pendingActionAtom); + layoutState.generation = get(generationAtom); return layoutState; }, - (_get, set, value) => { + (get, set, value) => { set(pendingActionAtom, value.pendingAction); - set(layoutNodeAtom, value.rootNode); + if (get(generationAtom) !== value.generation) set(layoutNodeAtom, value.rootNode); } ); } diff --git a/frontend/faraday/lib/layoutState.ts b/frontend/faraday/lib/layoutState.ts index cbeaa52a7..95606c779 100644 --- a/frontend/faraday/lib/layoutState.ts +++ b/frontend/faraday/lib/layoutState.ts @@ -36,6 +36,7 @@ export function newLayoutTreeState(rootNode: LayoutNode): LayoutTreeState< rootNode: balancedRootNode, leafs, pendingAction: undefined, + generation: 0, }; } @@ -77,12 +78,15 @@ function layoutTreeStateReducerInner(layoutTreeState: LayoutTreeState, act break; case LayoutTreeActionType.Move: moveNode(layoutTreeState, action as LayoutTreeMoveNodeAction); + layoutTreeState.generation++; break; case LayoutTreeActionType.InsertNode: insertNode(layoutTreeState, action as LayoutTreeInsertNodeAction); + layoutTreeState.generation++; break; case LayoutTreeActionType.DeleteNode: deleteNode(layoutTreeState, action as LayoutTreeDeleteNodeAction); + layoutTreeState.generation++; break; default: { console.error("Invalid reducer action", layoutTreeState, action); diff --git a/frontend/faraday/lib/model.ts b/frontend/faraday/lib/model.ts index 861effba4..e56b152e7 100644 --- a/frontend/faraday/lib/model.ts +++ b/frontend/faraday/lib/model.ts @@ -106,6 +106,7 @@ export type LayoutTreeState = { rootNode: LayoutNode; leafs: LayoutNode[]; pendingAction: LayoutTreeAction; + generation: number; }; /**