Skip to content

Commit 5619590

Browse files
authored
Merge pull request #78 from oslabs-beta/rydang/setStateChange
changed the way changeSetState operates
2 parents 9acde7d + 1a11e06 commit 5619590

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

package/__tests__/linkFiber.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('unit test for linkFiber', () => {
4747
});
4848

4949
test('linkFiber should modify the setState of the stateful component', () => {
50-
expect(snapShot.tree.children[0].component.setState.name).toBe('newSetState');
50+
expect(snapShot.tree.children[0].component.setState.linkFiberChanged).toBe(true);
5151
});
5252

5353
// test('newSetState should still setState correctly', () => {

package/linkFiber.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ module.exports = (snap, mode) => {
1717

1818
function changeSetState(component) {
1919
// check that setState hasn't been changed yet
20-
if (component.setState.name === 'newSetState') return;
20+
if (component.setState.linkFiberChanged) return;
2121

2222
// make a copy of setState
2323
const oldSetState = component.setState.bind(component);
2424

25-
function newSetState(state, callback = () => {}) {
25+
// replace component's setState so developer doesn't change syntax
26+
// component.setState = newSetState.bind(component);
27+
component.setState = (state, callback = () => {}) => {
2628
// dont do anything if state is locked
2729
// UNLESS we are currently jumping through time
2830
if (mode.locked && !mode.jumping) return;
@@ -32,10 +34,8 @@ module.exports = (snap, mode) => {
3234
sendSnapshot();
3335
callback();
3436
});
35-
}
36-
37-
// replace component's setState so developer doesn't change syntax
38-
component.setState = newSetState;
37+
};
38+
component.setState.linkFiberChanged = true;
3939
}
4040

4141
function createTree(currentFiber, tree = new Tree('root')) {

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-time-travel",
3-
"version": "1.0.4",
3+
"version": "1.1.0",
44
"description": "A library that helps debug React by memorizing the state of components with every render.",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)