Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm package now sends initial state at the very beginning #29

Merged
merged 1 commit into from
Jul 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions package/linkFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const Tree = require('./tree');

module.exports = (snap, mode) => {
let fiberRoot = null;
let first = true;

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

function newSetState(state, callback = () => { }) {
// continue normal setState functionality, except add sending message middleware
if (first) {
updateSnapShotTree();
sendSnapshot();
first = false;
}
oldSetState(state, () => {
updateSnapShotTree();
sendSnapshot();
Expand All @@ -47,8 +41,11 @@ module.exports = (snap, mode) => {
const { sibling, stateNode, child } = currentFiber;

let nextTree = tree;
// check if stateful component
if (stateNode && stateNode.state) {
// add component to tree
nextTree = tree.appendChild(stateNode);
// change setState functionality
changeSetState(stateNode);
}

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