Skip to content

Commit

Permalink
fixed foldState not updating on tree change
Browse files Browse the repository at this point in the history
  • Loading branch information
RobMayer committed Feb 3, 2024
1 parent 47c20cb commit 46c8054
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/lothlorien-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@playableprints/lothlorien-react",
"version": "0.2.1",
"version": "0.2.2",
"description": "",
"private": false,
"type": "module",
Expand All @@ -26,7 +26,7 @@
},
"homepage": "https://playableprints.github.io/lothlorien/index.html",
"dependencies": {
"@playableprints/lothlorien": "^0.2.1",
"@playableprints/lothlorien": "^0.2.2",
"valtio": "^1.13.0"
},
"peerDependencies": {
Expand Down
13 changes: 10 additions & 3 deletions packages/lothlorien-react/src/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ export const MetaProvider = ({ children, tree, startClosed = false, controls, on

const treeRef = useRef<Tree<any>>(tree);
useEffect(() => {
console.log("tree did update in Meta");
treeRef.current = tree;
markerValueRef.current = rebuildMarkers(tree);
markerSubs.current.forEach((cb) => cb());
foldSubs.current.forEach((cb) => cb());
}, [tree]);

const foldValueRef = useRef<{ [key: string]: boolean }>({});
Expand Down Expand Up @@ -185,12 +187,17 @@ export const MetaProvider = ({ children, tree, startClosed = false, controls, on
},
query: (nK: string) => {
//am I visible?
const p = treeRef.current.parentKey(nK);
if (p === undefined) {
return false;
}
if (p === null) {
return true;
}
return !treeRef.current
.ancestorKeys(nK)
.reverse()
.some((aKey, i, ary) => {
return !(foldValueRef.current[aKey] ?? (i === ary.length - 1 ? false : defaultFoldRef.current));
});
.some((each) => !(foldValueRef.current[each] ?? defaultFoldRef.current));
},
get: (nK: string) => {
return foldValueRef.current[nK] ?? defaultFoldRef.current;
Expand Down
2 changes: 1 addition & 1 deletion packages/lothlorien/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@playableprints/lothlorien",
"version": "0.2.1",
"version": "0.2.2",
"description": "",
"private": false,
"type": "module",
Expand Down

0 comments on commit 46c8054

Please sign in to comment.