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

make autosubscribing to a nullish store a no-op #4304

Merged
merged 3 commits into from
Jan 23, 2020

Conversation

Conduitry
Copy link
Member

Resolves #2181.

This adds a very slight cost in terms of per-app bytes (and adds an extra == null test each time we subscribe to a component via the subscribe() helper) - and it's possible that this will mask genuine bugs or logic errors in components - but I still think we're better off with this.

With this PR, you're allowed to have autosubscribed stores that don't immediately have values, which, in addition to what's described in #2181, also lets you more easily use a series of reactive declarations to grab something from nested stores.

If this is merged, we should probably also document the new behavior somewhere beyond the changelog, but I'm not sure where.

@Conduitry
Copy link
Member Author

As a side effect of #4300, this would also mean that you're allowed to use nullish values as dependencies in derived stores, and they'll just be treated as stores containing undefined. This doesn't seem desirable in particular, but it also doesn't seem undesirable enough to do much about.

@Rich-Harris Rich-Harris merged commit f01bb63 into sveltejs:master Jan 23, 2020
@Conduitry Conduitry deleted the gh-2181 branch January 24, 2020 14:45
jesseskinner pushed a commit to jesseskinner/svelte that referenced this pull request Feb 27, 2020
* make autosubscribing to a nullish store a no-op (sveltejs#2181)

* update changelog

* add test
taylorzane pushed a commit to taylorzane/svelte that referenced this pull request Dec 17, 2020
* make autosubscribing to a nullish store a no-op (sveltejs#2181)

* update changelog

* add test
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.

"Cannot read property 'subscribe' of undefined" when store creation is delayed
2 participants