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 component names like <Foo.Bar.Baz>? #2484

Closed
Rich-Harris opened this issue Apr 22, 2019 · 1 comment
Closed

Allow component names like <Foo.Bar.Baz>? #2484

Rich-Harris opened this issue Apr 22, 2019 · 1 comment

Comments

@Rich-Harris
Copy link
Member

Was just playing around with an interpretation of React's createContext/useContext API:

https://svelte.dev/repl?version=3.0.0&gist=2a110c18df550964f9b31aa2425eaaf1

I think it works pretty well, if you prefer that sort of thing to the standard context API, but it might be nice if App.svelte looked like this instead:

<script>
	import ChildComponent from './ChildComponent.svelte';
-	import { Provider } from './ThemeContext.js';
+	import ThemeContext from './ThemeContext.js';
	
	let theme = 'light';
</script>

<select bind:value={theme}>
	<option>light</option>
	<option>dark</option>
</select>

<ThemeContext.Provider value={theme}>
  <ChildComponent />
</ThemeContext.Provider>

I can see this being useful in other scenarios as well, e.g. if a package exported multiple components that were designed to be used together:

<script>
	import * as Funky from 'funky-ui';
</script>

<Funky.Dropdown>
	<Funky.Option>one</Funky.Option>
	<Funky.Option>two</Funky.Option>
	<Funky.Option>three</Funky.Option>
</Funky.Dropdown>
@Conduitry
Copy link
Member

This was implemented in #2743.

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

No branches or pull requests

2 participants