Skip to content

Commit

Permalink
100 Remember subscriptions from previous render
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgilbertson committed Mar 20, 2020
1 parent 928b194 commit bdf1b97
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/collect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const componentStack: CollectorComponent[] = [];
const startRecordingGetsForComponent = (component: CollectorComponent) => {
if (!state.isInBrowser) return;

removeListenersForComponent(component);

debug(() => {
console.groupCollapsed(`RENDER: <${component._name}>`);
});
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/TaskListTest/Task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Props = {
task: TaskType;
};

const Task = ({ task }: Props) => (
const Task = React.memo(({ task }: Props) => (
<div>
<label>
<input
Expand All @@ -32,6 +32,6 @@ const Task = ({ task }: Props) => (
Delete {task.name}
</button>
</div>
);
));

export default Task;
16 changes: 13 additions & 3 deletions tests/integration/TaskListTest/TaskList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ it('TaskList', async () => {
await findByText('Task one');

// it should mark a task as done in a child component
const checkbox = getByLabelText('Task one') as HTMLInputElement;
const taskOneCheckbox = getByLabelText('Task one') as HTMLInputElement;

expect(checkbox.checked).toBe(false);
expect(taskOneCheckbox.checked).toBe(false);

getByLabelText('Task one').click();

expect(checkbox.checked).toBe(true);
expect(taskOneCheckbox.checked).toBe(true);

// the component should still be listening to other tasks. See bug:
// https://github.com/davidgilbertson/react-recollect/issues/100
const taskTwoCheckbox = getByLabelText('Task two') as HTMLInputElement;

expect(taskTwoCheckbox.checked).toBe(false);

getByLabelText('Task two').click();

expect(taskTwoCheckbox.checked).toBe(true);

// it should delete a task from a child component
getByText('Delete Task one').click();
Expand Down

0 comments on commit bdf1b97

Please sign in to comment.