-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Self referencing derived store #4880
Comments
wow @pushkine - that's a nice workaround! time to refactor again :D |
@antony I'm not seeing any warnings or exceptions with your REPL. |
@Conduitry break it - change |
can't replicate the bug, removing the bug label |
Looks like #6737 is related to this; either a duplicate, or an overlapping request. If the optional second parameter of export const first = writable({ value: 1 })
const second = derived([ first ], ([ $first ], set) => {
set({ value: $first.value + 1 })
})
export const third = derived([ second ], async ([ $second ], (set, update)) => {
console.log('deriving third value')
update($third => ({ $third.value + $second.value }))
}, { value: 1 }) |
Describe the bug
This is half bug, half proposal.
The current implementation of derived stores doesn't provide a way to use the store's existing value in the new value (a-la
.update
).You can see in the REPL my workaround for this is to use
get(storeName)
which... sort of works.The issue is that you get a console error which pertains to whatever the error you previously encountered was, which is written every time the store updates.
Logs
To Reproduce
https://svelte.dev/repl/df25b5983b8d464fb1e47af7a1d12d61?version=3.22.3
Expected behavior
The current behaviour is correct, aside from the error.
Information about your Environment:
Severity
I do need to use the current store value in a derived store, as my derived store builds a set of results which need to be concatenated. I can work around it though, so:
low
The text was updated successfully, but these errors were encountered: