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

Fix unwatch multiple signals #26

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

tuhm1
Copy link
Contributor

@tuhm1 tuhm1 commented Jul 1, 2024

Fixes #2

The issue arises when removing an element, which shifts the last element to the current index. As a result, the last index goes out of bounds, and the moved element remains unprocessed.

To address this, iterate backward so that the removed element is replaced with a checked element, while the others remain unchanged.

Copy link
Contributor

@ds300 ds300 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Thanks for the fix :)

Comment on lines +235 to +237
const lastIdx = node.producerNode!.length - 1;
node.producerNode![i] = node.producerNode![lastIdx];
node.producerIndexOfThis[i] = node.producerIndexOfThis[lastIdx];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this stuff can be skipped if lastIdx === i

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, but I believe it won't make any difference. I prefer to implement only the necessary changes needed to fix the issue, making it easier for the owner to review.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I certainly appreciate that! I also think it would make this code path slightly easier to read if the special case where the producer is the last item in the array was more clearly delineated like it is below the linked snippet.

expect(notify).toHaveBeenCalledTimes(expectedNotifyCalls);

watcher.watch();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i might just add expect(expectedNotifyCalls).toBe(3) at the end here just to be clear.

Copy link
Contributor Author

@tuhm1 tuhm1 Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the suggestion, but I think it's not really necessary, considering the logic and other checks.

@littledan
Copy link
Contributor

@ds300 Do you recommend landing this change? Does it overlap with/obviate #24?

@ds300
Copy link
Contributor

ds300 commented Jul 8, 2024

@littledan yeah this is good to land I think. The other PR should be closed, it adds some dubious sanity checks but doesn't fix any bugs as far as I can tell (actually it seems to add code that would swallow legitimate errors in some cases).

@Roeck
Copy link

Roeck commented Jul 8, 2024

@ds300 Just to clarify, I've tested these changes thoroughly, and they don't introduce any new issues. These sanity checks are not meant to hide real errors but to prevent the feature from breaking when it encounters unusual situations.

@littledan littledan merged commit 76c75c3 into proposal-signals:main Jul 23, 2024
3 checks passed
@github-actions github-actions bot mentioned this pull request Jun 24, 2024
@littledan littledan mentioned this pull request Jul 23, 2024
@NullVoxPopuli NullVoxPopuli added the bug Something isn't working label Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Batch unsubscribe issue
5 participants