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 setContext return the value that was just set. #7427

Closed
gtm-nayan opened this issue Apr 7, 2022 · 1 comment · Fixed by #7432
Closed

Make setContext return the value that was just set. #7427

gtm-nayan opened this issue Apr 7, 2022 · 1 comment · Fixed by #7432
Labels
feature request runtime Changes relating to runtime APIs

Comments

@gtm-nayan
Copy link
Contributor

gtm-nayan commented Apr 7, 2022

Describe the problem

It is a common pattern to put stores into context for reactivity, even the docs recommend it, however there is one mildly annoying thing when you want to use that store within the same component. See the examples below (imports removed for brevity):

This one sparks joy (not possible currently)

<script>
	const my_store_thing = setContext(key, writable());
</script>

Do stuff with {$my_store_thing} in the same component.

This one does not

<script>
	const my_store_thing = writable();
	setContext(key, my_store_thing); // my_store_thing is repeated here.
</script>

Do stuff with {$my_store_thing} in the same component.

Describe the proposed solution

Make setContext return the value that was passed into it as the second argument. Should be a non breaking change AFAIK unless people are doing weird things with it.

Alternatives considered

Leave things as is.

Importance

would make my life easier

@Conduitry
Copy link
Member

This is happening now in 3.48.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request runtime Changes relating to runtime APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants