You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if you want to autosubscribe to a, it's simple, you just do $a, but if you want to subscribe to b.c, there is problem.
b.$c// returns undefined$(b.c)// invalid syntax (it thinks `$` is function) instead `()` being to explicitly ordering how code is evaluated${...b.c}// could work (or without {}), but doesn't work, syntax error
so if we want to autosubscribe to these methods, we must first extract store to variable.
Describe the proposed solution
Spread operator seems like cool feature for extracting properties from objects or arrays, so I propose feature:
$...a.b that would read property b inside object a, and subscribe to store that is inside of propety. $...a[0] would subscribe to store that is inside array at index 0.
This would give ability to subscribe to really any store inside component, even that, that is inside object that is inside array...
in case of having:
consta={b: writable({c: 'hello'})}
we would access it with: ($...a.b).c syntax, or similiar way for array: ($...a.b)[0]
Alternatives considered
Using () to tell what has greater priority in order of evaluation and allowing $() syntax, that looks like function, but would not be function. Aka $(b[0]) would fisrt extract index 0 from array b, and then subscribe to it. or $(b.c) will subscribe to store that is inside c in object b.
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered:
ups, can you move it to Svelte repo, somehow I put it to wrong one.
Mlocik97
changed the title
Autosubscription doesn't work with array of stores or stores inside objects
Autosubscription doesn't work with array of stores or stores inside objects, add $... syntax to make it work
Apr 2, 2022
Mlocik97
changed the title
Autosubscription doesn't work with array of stores or stores inside objects, add $... syntax to make it work
Autosubscription doesn't work with array of stores or stores inside objects, add $...a.b or $(a.b) syntax to make it work
Apr 2, 2022
I'm going to close this one as there are already a couple of open issues discussing alternative syntaxes for store subscriptions at sveltejs/svelte#4079 and sveltejs/svelte#6373.
Describe the problem
Let say we have something like this:
if you want to autosubscribe to a, it's simple, you just do
$a
, but if you want to subscribe to b.c, there is problem.in case of array, it's same problem, doing
so if we want to autosubscribe to these methods, we must first extract store to variable.
Describe the proposed solution
Spread operator seems like cool feature for extracting properties from objects or arrays, so I propose feature:
$...a.b
that would read property b inside object a, and subscribe to store that is inside of propety.$...a[0]
would subscribe to store that is inside array at index 0.This would give ability to subscribe to really any store inside component, even that, that is inside object that is inside array...
in case of having:
we would access it with:
($...a.b).c
syntax, or similiar way for array:($...a.b)[0]
Alternatives considered
Using
()
to tell what has greater priority in order of evaluation and allowing$()
syntax, that looks like function, but would not be function. Aka$(b[0])
would fisrt extract index 0 from array b, and then subscribe to it. or$(b.c)
will subscribe to store that is inside c in object b.Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: