Skip to content

Commit 2af846d

Browse files
authored
Merge pull request #29 from oslabs-beta/rydang/treeinitial
npm package now sends initial state at the very beginning
2 parents 511a32f + 846a344 commit 2af846d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

package/linkFiber.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const Tree = require('./tree');
44

55
module.exports = (snap, mode) => {
66
let fiberRoot = null;
7-
let first = true;
87

98
function sendSnapshot() {
109
// don't send messages while jumping
@@ -25,11 +24,6 @@ module.exports = (snap, mode) => {
2524

2625
function newSetState(state, callback = () => { }) {
2726
// continue normal setState functionality, except add sending message middleware
28-
if (first) {
29-
updateSnapShotTree();
30-
sendSnapshot();
31-
first = false;
32-
}
3327
oldSetState(state, () => {
3428
updateSnapShotTree();
3529
sendSnapshot();
@@ -47,8 +41,11 @@ module.exports = (snap, mode) => {
4741
const { sibling, stateNode, child } = currentFiber;
4842

4943
let nextTree = tree;
44+
// check if stateful component
5045
if (stateNode && stateNode.state) {
46+
// add component to tree
5147
nextTree = tree.appendChild(stateNode);
48+
// change setState functionality
5249
changeSetState(stateNode);
5350
}
5451

@@ -68,5 +65,6 @@ module.exports = (snap, mode) => {
6865
const { _reactRootContainer: { _internalRoot } } = container;
6966
fiberRoot = _internalRoot;
7067
updateSnapShotTree();
68+
sendSnapshot();
7169
};
7270
};

0 commit comments

Comments
 (0)