Skip to content

Commit

Permalink
[Shallow] Rename effect cleanup function to destroy to match rest of …
Browse files Browse the repository at this point in the history
…react (facebook#15275)
  • Loading branch information
insidewhy committed Jul 26, 2019
1 parent b029466 commit c486479
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions packages/react-test-renderer/src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class ReactShallowRenderer {
isLayoutEffect,
create,
inputs,
cleanup: null,
destroy: null,
run: true,
};
} else {
Expand All @@ -343,7 +343,7 @@ class ReactShallowRenderer {
isLayoutEffect,
create,
inputs,
cleanup: memoizedState.cleanup,
destroy: memoizedState.destroy,
run:
inputs == null ||
!areHookInputsEqual(inputs, memoizedState.inputs),
Expand Down Expand Up @@ -754,10 +754,10 @@ class ReactShallowRenderer {
memoizedState.isLayoutEffect === callLayoutEffects &&
memoizedState.run
) {
if (memoizedState.cleanup) {
memoizedState.cleanup();
if (memoizedState.destroy) {
memoizedState.destroy();
}
memoizedState.cleanup = memoizedState.create();
memoizedState.destroy = memoizedState.create();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ describe('ReactShallowRenderer with hooks', () => {
]);
});

it('should trigger effects and cleanup depending on inputs', () => {
it('should trigger effects and destroy depending on inputs', () => {
let _setFriend;
const happenings = [];

Expand All @@ -294,7 +294,7 @@ describe('ReactShallowRenderer with hooks', () => {
() => {
happenings.push('call friend effect');
return () => {
happenings.push('cleanup friend effect');
happenings.push('destroy friend effect');
};
},
[friend],
Expand All @@ -303,15 +303,15 @@ describe('ReactShallowRenderer with hooks', () => {
React.useEffect(() => {
happenings.push('call empty effect');
return () => {
happenings.push('cleanup empty effect');
happenings.push('destroy empty effect');
};
});

React.useEffect(
() => {
happenings.push('call cat effect');
return () => {
happenings.push('cleanup cat effect');
happenings.push('destroy cat effect');
};
},
[cat],
Expand All @@ -321,7 +321,7 @@ describe('ReactShallowRenderer with hooks', () => {
() => {
happenings.push('call both effect');
return () => {
happenings.push('cleanup both effect');
happenings.push('destroy both effect');
};
},
[friend, cat],
Expand All @@ -347,11 +347,11 @@ describe('ReactShallowRenderer with hooks', () => {
happenings.splice(0);
_setFriend('Maryam');
expect(happenings).toEqual([
'cleanup friend effect',
'destroy friend effect',
'call friend effect',
'cleanup empty effect',
'destroy empty effect',
'call empty effect',
'cleanup both effect',
'destroy both effect',
'call both effect',
]);
});
Expand Down

0 comments on commit c486479

Please sign in to comment.