Closed Rich-Harris closed 5 years ago
Will equivalents to component.root & component.options be available?
Will equivalents to component.root & component.options be available?
There's no way to do that currently in this RFC. We should consider what the use cases are so that we can figure out if it's necessary, or if there's a better way.
The svelte:meta
element seems like a great way to get the component's state as an object, or even just get the props that were passed in:
<svelte:meta bind:state bind:props bind:options bind:root=parent />
<script>
const cool = true
console.log(state.cool)
</script>
My original thought was to use ref
instead of bind
, but bind
seems better. @Conduitry noted that already uses the bind
directive for one-way binding, so it doesn't seem too weird here.
Yes, I like the <svelte:meta>
idea. Idiomatic, easy to compile.
I don't think we'd want it to make those names magically available in <script>
though — I think we'd want to handle it the same way this RFC proposes we handle refs:
<script>
import Widget from './Widget.html';
let props;
let options;
let canvas;
onmount(() => {
console.log(props, options, canvas);
});
onprops(() => {
console.log(props);
});
</script>
<svelte:meta bind:props bind:options/>
<canvas ref:canvas></canvas>
<Widget {...props}/>
We probably don't want a binding for state
. props
makes sense, as does root
. Not entirely sold on options
— it'd be nice if we were free to use a more optimal private API for inline components, rather than the public API (which would also prevent us from doing certain optimisations like component folding).
Oh, I'd somehow missed that bit about needing to define the variable with let
for refs.
Yeah, that would make TypeScript type waaaaaay simpler.
Sorry everyone, I did a bad git. I've opened a new PR for this RFC — #4. I think most of the comments in this thread have been addressed in any case; the big TODO is Store, which we can discuss over there.
Moved to #4
A proposal for simpler, smaller components with a new approach to reactivity.
View formatted RFC
See also the original issue https://github.com/sveltejs/svelte/issues/1826