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

state is now recorded into snapshot whenever this.setState is called. also snapshot is sent to window #6

Merged
merged 3 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
.DS_Store
dist/
extension/bundle.js
package/react-time-travel-1.0.1.tgz
testing
13 changes: 13 additions & 0 deletions package/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const snapShot = [];

window.addEventListener('message', ({ data: { action, payload } }) => {
if (action === 'jumpToSnap') {
console.log('snap received from chrome', payload);
}
});

const linkState = require('./linkState')(snapShot);

module.exports = {
linkState,
};
29 changes: 29 additions & 0 deletions package/linkState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// links component state to library
// changes the setState method to also update our snapshot

module.exports = (snapShot) => {
function sendSnapShot() {
const payload = snapShot.map(comp => comp.state);
window.postMessage({
action: 'recordSnap',
payload,
});
}

return (component) => {
snapShot.push(component);

sendSnapShot();

const oldSetState = component.setState.bind(component);

function newSetState(state, callback = () => { }) {
oldSetState(state, () => {
sendSnapShot();
callback();
});
}

component.setState = newSetState;
};
};
5 changes: 0 additions & 5 deletions package/package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-time-travel",
"version": "1.0.0",
"version": "1.0.1",
"description": "A library that helps debug React by memorizing the state of components with every render.",
"main": "index.js",
"repository": {
Expand Down