solid icon indicating copy to clipboard operation
solid copied to clipboard

on() not triggered when using a mutable store item as a dependency

Open chvelkov opened this issue 2 years ago • 1 comments

Describe the bug

Here's an example:

Your Example Website or App

https://playground.solidjs.com/anonymous/64e29718-38db-4df4-afeb-4445b799d170

Steps to Reproduce the Bug or Issue

Press Increment

Expected behavior

When pressing the button I'd expect that both counters update, however the one using on() isn't working.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

chvelkov avatar Jul 31 '23 17:07 chvelkov

Yeah this is akin to setting a value at an index in createStore whereas the way you generally do this is spread in a new array. https://playground.solidjs.com/anonymous/6ea855b3-1f2d-4dc6-a9c0-e413b6258e64

It notifies things that listen to the index but not everything. The thing is that something that would change the length probably should trigger the parent.. we use length actually as a trick for this as iteration depends on it which means it works in all cases other than on which doesn't iterate. And since on is a blanket reactive wrapper (ie can return anything not just the thing that is accessed) there isn't really a way to address this on the on side.

The fact that produce is also impacted suggests this is something we should consider changing if feasible. Thanks for bringing this to my attention. I never use on or mutable interfaces so this wasn't in my direct thinking.

I guess this is our version of Svelte's

array.push(1);
array = array;

ryansolid avatar Aug 01 '23 21:08 ryansolid