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

Allow getContext() to pass on context as a whole #6447

Closed
dummdidumm opened this issue Jun 25, 2021 · 2 comments · Fixed by #6528
Closed

Allow getContext() to pass on context as a whole #6447

dummdidumm opened this issue Jun 25, 2021 · 2 comments · Fixed by #6528

Comments

@dummdidumm
Copy link
Member

dummdidumm commented Jun 25, 2021

Is your feature request related to a problem? Please describe.
I want to pass on context to programatically defined components:

new SomeComponent({target, props, context: ??? })

Describe the solution you'd like
Allow getContext to be called without a key, which means the whole Map is returned. This would allow me to do

const context = getContext();
// somewhere in onMount..
   new SomeComponent({target, props, context })

The alternative is to provide a distinct function like getContexts

Describe alternatives you've considered
Don't know of any

How important is this feature to you?
Medium. It's important for programatically creating new components which share the same context, but a workaround exists, which is copying these over by hand.

Additional info
Related to #3615

@Rich-Harris
Copy link
Member

mentioned in discord, but leaving a note here as well: i think this should be getAllContexts() or getContexts(), since functions that significantly change their behaviour based on the number of arguments they receive are generally an anti-pattern, I think — they don't tend to stand the test of time in my experience

@Conduitry
Copy link
Member

Added in 3.39.0, in the getAllContexts() form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants