Skip to content

Commit 4a30a17

Browse files
committed
automatically reload node and code when necessary
now Assemble experience is great
1 parent f1c9548 commit 4a30a17

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

solid_node/viewers/web/app/src/App.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ const App = () => {
4949
loadNode(path, context).then((node) => {
5050
setNode(node);
5151
setAnimator(Animator.getInstance(setTime));
52-
setReloader(new Reloader(setError, () => {
53-
node.reload();
52+
setReloader(new Reloader(setError, async () => {
53+
const newNode = await node.reload();
54+
if (newNode !== undefined) {
55+
setNode(newNode);
56+
}
5457
}));
5558
});
5659
}, []);

solid_node/viewers/web/app/src/node.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,22 @@ export abstract class Node {
113113
}
114114
}
115115

116-
async reload() {
116+
async reload(): Promise<Node | undefined> {
117117
this.loadModel();
118-
//const nodeData = await loadNodeData(this.path);
118+
try {
119+
const nodeData = await loadNodeData(this.path);
120+
if (this.code != nodeData.code) {
121+
this.code = nodeData.code;
122+
this.newCode = this.code;
123+
}
124+
const scene = this.context.scene;
125+
while(scene.children.length > 0) {
126+
scene.remove(scene.children[0]);
127+
}
128+
return await loadNode(this.path, this.context);
129+
} catch (e) {
130+
return undefined;
131+
}
119132
}
120133

121134
loadModel() {

0 commit comments

Comments
 (0)