Reputation: 7097
Here's a simplified version of my context:
bookmarks [{title, url}, ...]
bookmarks
by adding a new property with the domain name of the url: `xbookmarks = [{title, url, domain}, ...]filter: {domains: {domain:true|false, ...}}
variablefilter.domains
map is populated in a reactive statement by iterating over xbookmarks
and setting all domains to true
filterdBookmarks
variable is computed in a reactive statement by filtering xbookmarks
using filter
Here's the flow in pseudo-javascript:
let bookmarks=[]
let xbookmarks=[]
$: xbookmarks = bookmarks.map(b=>{...b, domain: computeDomain(b)})
let filter = {domains: {}}
$: filter.domains=extractDomains(xbookmarks)
let filterdBookmarks=[]
$: filterBookmarks = xbookmarks.filter(using filter)
Here's a link to the svelte REPL with the complete code described above: https://svelte.dev/repl/d07ffc88e4a34cb797d2ceb6ba0ec6a4?version=3.49.0
When I try to uncheck one of the domains checkboxes:
filter
changed => trigger recomputation of depending variables, i.e. filterdBookmarks
filter
changed => Svelte recomputes xbookmarks
, then filter.domains
which resets it back to all domains being checked, then filterdBookmarks
I can't understand why Svelte considers that xbookmarks
depends on filter
When I looked into the JS code generated by Svelte, this shouldn't be happening:
As can be seen in the screenshot above, the generated code matches my intuition about the dependencies:
xbookmarks
is recomputed when bookmarks
changesfilter.domains
is recomputed when xbookmarks
changesfilteredBookmarks
is recomputed when either of filter
of xbookmarks
changesP.S.: I have just started learning and playing with Svelte
Upvotes: 3
Views: 239
Reputation: 185140
This is probably a bug. The input_change_handler
invalidates too many variables.
This worked in v.3.2.0, see also this related question and issue opened for it.
Upvotes: 3