Skip to content

Commit 24e511f

Browse files
authored
Merge pull request #75 from oslabs-beta/staging
Staging
2 parents 28d6181 + 6abc547 commit 24e511f

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/backend/linkFiber.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ import 'core-js';
3737
// const Tree = require('./tree').default;
3838
// const componentActionsRecord = require('./masterState');
3939

40-
import { Snapshot, Mode, SnapshotNode, MsgData, ComponentData, HookStates, Fiber, WorkTag, State } from './types/backendTypes'
40+
import {
41+
Snapshot, Mode, SnapshotNode, MsgData, ComponentData, HookStates, Fiber, WorkTag, State
42+
} from './types/backendTypes';
4143
import Tree from './tree';
4244
import componentActionsRecord from './masterState';
4345
import { throttle, getHooksNames } from './helpers';
4446

45-
let doWork: boolean = true;
47+
let doWork = true;
4648
const circularComponentTable = new Set();
4749

4850
// module.exports = (snap, mode) => {
@@ -57,7 +59,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
5759
snap.tree = new Tree('root', 'root');
5860
}
5961
const payload = snap.tree.cleanTreeCopy();// snap.tree.getCopy();
60-
62+
6163
window.postMessage({
6264
action: 'recordSnap',
6365
payload,
@@ -86,7 +88,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
8688
}
8789

8890
// This runs after every Fiber commit. It creates a new snapshot
89-
function createTree(currentFiber: Fiber, tree: Tree = new Tree('root', 'root'), fromSibling: boolean = false) {
91+
function createTree(currentFiber: Fiber, tree: Tree = new Tree('root', 'root'), fromSibling = false) {
9092
// Base case: child or sibling pointed to null
9193
if (!currentFiber) return null;
9294
if (!tree) return tree;
@@ -108,7 +110,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
108110

109111
let newState: any;
110112
let componentData: ComponentData;
111-
let componentFound: boolean = false;
113+
let componentFound = false;
112114

113115
// Check if node is a stateful setState component
114116
if (stateNode && stateNode.state && (tag === 0 || tag === 1 || tag === 2)) {
@@ -144,7 +146,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
144146
}
145147

146148
// This grabs stateless components
147-
149+
148150
if (!componentFound && (tag === 0 || tag === 1 || tag === 2)) {
149151
newState = 'stateless';
150152
}
@@ -160,7 +162,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
160162

161163
let newNode = null;
162164
// We want to add this fiber node to the snapshot
163-
const snapshotState = newState.state || newState.hooksState ;
165+
//const snapshotState = newState.state || newState.hooksState;
164166
if (componentFound || newState === 'stateless') {
165167
if (fromSibling) {
166168
newNode = tree.addSibling(newState,
@@ -175,7 +177,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
175177
newNode = tree;
176178
}
177179

178-
// Recurse on children
180+
// Recurse on children
179181
if (child && !circularComponentTable.has(child)) {
180182
// If this node had state we appended to the children array,
181183
// so attach children to the newly appended child.
@@ -206,7 +208,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
206208
console.log('doWork is:', doWork);
207209
}
208210

209-
return () => {
211+
return () => {
210212
/* const container = document.getElementById('root');
211213
if (container._internalRoot) {
212214
fiberRoot = container._internalRoot;
@@ -223,7 +225,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
223225
const reactInstance = devTools ? devTools.renderers.get(1) : null;
224226
fiberRoot = devTools.getFiberRoots(1).values().next().value;
225227
const throttledUpdateSnapshot = throttle(updateSnapShotTree, 140);
226-
228+
227229
document.addEventListener('visibilitychange', onVisibilityChange);
228230
if (reactInstance && reactInstance.version) {
229231
devTools.onCommitFiberRoot = (function (original) {

src/backend/tree.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import 'core-js';
55
/* eslint-disable no-param-reassign */
66

77
// import * as reactWorkTags from './reactWorkTags';
8-
//const Flatted = require('flatted');
8+
// const Flatted = require('flatted');
99

10-
let copyInstances: number = 0;
11-
const circularComponentTable = new Set<Tree> ();
10+
let copyInstances = 0;
11+
const circularComponentTable = new Set<Tree>();
1212

1313
// removes unserializable state data such as functions
1414
function scrubUnserializableMembers(tree: Tree): Tree {
@@ -21,26 +21,31 @@ function scrubUnserializableMembers(tree: Tree): Tree {
2121
// this is the current snapshot that is being sent to the snapshots array.
2222
class Tree {
2323
state: string | {};
24+
2425
name: string;
26+
2527
componentData: {};
28+
2629
children: (Tree | string)[] ;
30+
2731
parent: Tree
28-
constructor(state : string | {}, name: string = 'nameless', componentData: {} = {}) {
32+
33+
constructor(state : string | {}, name = 'nameless', componentData: {} = {}) {
2934
this.state = state === 'root' ? 'root' : JSON.parse(JSON.stringify(state));
3035
this.name = name;
3136
this.componentData = componentData ? JSON.parse(JSON.stringify(componentData)) : {};
3237
this.children = [];
3338
this.parent = null; // ref to parent so we can add siblings
3439
}
3540

36-
addChild(state: string | {} , name: string, componentData: {}): Tree {
41+
addChild(state: string | {}, name: string, componentData: {}): Tree {
3742
const newChild: Tree = new Tree(state, name, componentData);
3843
newChild.parent = this;
3944
this.children.push(newChild);
4045
return newChild;
4146
}
4247

43-
addSibling(state: string | {} , name: string, componentData: {}): Tree {
48+
addSibling(state: string | {}, name: string, componentData: {}): Tree {
4449
const newSibling: Tree = new Tree(state, name, componentData);
4550
newSibling.parent = this.parent;
4651
this.parent.children.push(newSibling);
@@ -62,14 +67,14 @@ class Tree {
6267
// copy.children = this.children;
6368

6469
// creates copy of each child of the present node
65-
70+
6671
copy.children = this.children.map((child: Tree): Tree | string => {
67-
if (!circularComponentTable.has(child)) {
68-
return child.cleanTreeCopy();
69-
}
70-
return 'circular';
72+
if (!circularComponentTable.has(child)) {
73+
return child.cleanTreeCopy();
74+
}
75+
return 'circular';
7176
});
72-
77+
7378

7479
// returns copy
7580
copyInstances--;

0 commit comments

Comments
 (0)