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] set auto-subscription to undefined when update store to falsy value #7693

Closed
wants to merge 2 commits into from

Conversation

tanhauhau
Copy link
Member

Fixes #7555

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with [feat], [fix], [chore], or [docs].
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

Copy link
Member

@baseballyama baseballyama left a comment

Choose a reason for hiding this comment

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

LGTM! I posted 1 question.

Comment on lines +75 to +82
export function subscribe_dynamic_store(store, callback) {
if (store == null) {
callback(undefined);
return noop;
}
const unsub = store.subscribe(callback);
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}
Copy link
Member

Choose a reason for hiding this comment

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

[ask]

This is a question but why did you create the new function?
Why adding callbacks.forEach(callback => callback(undefined)); to subscribe is not good?

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry didn't understand the question.

You are saying using what statement instead of which function?

Copy link
Member

Choose a reason for hiding this comment

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

Already we have subscribe function.
And the difference between subscribe_dynamic_store and subscribe is only line number 77. (callback(undefined);)

So I thought that we can update subscribe without creating the new function subscribe_dynamic_store.
But I believe you have a reason why subscribe_dynamic_store is necessary. So I would like to know about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm.. I can't remember why I did that.
I know we need to call callback(undefined) so that when store changed to undefined, we should update $store to undefined too.

The subscribe was used when it assumes that the store variable is static, so does not need to call callback to set the $store to undefined.

But let me look at it again and see if I can reuse the code.

@Conduitry
Copy link
Member

There was another PR #7947 opened for what appears to be a duplicate issue (#7946) which looks simpler, but I haven't really thought about the two different implementations.

@tanhauhau
Copy link
Member Author

Close in favor of #7947

@tanhauhau tanhauhau closed this Oct 16, 2022
@tanhauhau tanhauhau deleted the tanhauhau/gh-7555 branch October 16, 2022 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting a store to null does not update auto-subscription references
3 participants