I've been trying to achieve a specific functionality with my objects. Even if the code isn't functioning correctly, I hope you can grasp the intention.
In Nested.svelte, I have this component with the specified coordinates:
<script lang=ts>
export let pos: {
x: number,
y: number,
}
</script>
Each nested component in my program is displayed like this in App.svelte:
{#each objects as object}
<Nested bind:pos.x={object.geometry.x} bind:pos.y={object.geometry.y}
{/each}
The objects
variable holds a store value structured as follows:
objects.geometry = [
{
x,
y,
}, {
x,
y,
} ...
]
The issue lies in passing objects.geometry.x
and objects.geometry.y
to the Nested component from the App. The provided code does not function properly, and the only workaround I have found is passing the entire object:
<Nested bind:pos={objects.geometry}>
. However, this method does not allow me to bind specific values in App to specific values in Nested. It also requires that the variables in the objects
variable have the same names as the coordinate values in Nested.svelte (x
and y
).
Is there an alternative way to pass object-structured data into components? Perhaps something that would operate similar to
<Nested bind:pos.x={object.geometry.x} bind:pos.y={object.geometry.y}
?