Skip to content

Commit 17d8d91

Browse files
committed
sending snapshot tree is better formatted
1 parent 6a8cfb8 commit 17d8d91

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

package/timeJump.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = (origin, mode) => {
1313
const originNode = traverseTree(origin.tree, coords);
1414

1515
// set the state of the origin tree
16-
originNode.component.setState(target.component.state, () => {
16+
originNode.component.setState(target.state, () => {
1717
// iterate through new children once state has been set
1818
target.children.forEach((child, i) => {
1919
jump(child, coords.concat(i));

package/tree.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
class Tree {
2-
constructor(component, useStateInstead = false) {
2+
constructor(component, useStateInstead = false, name) {
33
// special case when component is root
44
// give it a special state = 'root'
55
// a setState function that just calls the callback instantly
66
if (!useStateInstead) {
77
this.component = (component === 'root') ? { state: 'root', setState: (partial, callback) => callback() } : component;
88
} else {
99
this.state = component;
10+
this.name = name;
1011
}
1112
this.children = [];
1213
}
@@ -18,9 +19,9 @@ class Tree {
1819
}
1920

2021
// deep copies only the state of each component and creates a new tree
21-
getCopy(copy = new Tree('root', true)) {
22+
getCopy(copy = new Tree('root', true, 'root')) {
2223
// copy state of children
23-
copy.children = this.children.map(child => new Tree(child.component.state, true));
24+
copy.children = this.children.map(child => new Tree(child.component.state, true, child.component.constructor.name));
2425

2526
// copy children's children recursively
2627
this.children.forEach((child, i) => child.getCopy(copy.children[i]));
@@ -31,10 +32,13 @@ class Tree {
3132
print() {
3233
const children = ['children: '];
3334
this.children.forEach((child) => {
34-
children.push(child.component.state);
35+
children.push(child.state || child.component.state);
3536
});
36-
if (children.length === 1) console.log(this.component.state);
37-
else console.log(this.component.state, ...children);
37+
if (this.name) console.log(this.name);
38+
if (children.length === 1) {
39+
console.log(this.state || this.component.state);
40+
}
41+
else console.log(this.state || this.component.state, ...children);
3842
this.children.forEach((child) => {
3943
child.print();
4044
});

0 commit comments

Comments
 (0)