updating a member inside another member inside an array inside a store using an index

o/ so i have data structured as follows, which is inside a store:
{
actions: [
{
data: {...}
}
]
}
{
actions: [
{
data: {...}
}
]
}
when i do this:
setStore(
"actions",
i.index,
"data",
block.data
)
setStore(
"actions",
i.index,
"data",
block.data
)
modifying works fine. but i have an effect subscribed to it
createEffect(() => {
console.log(store)
console.log(store.actions)
})
createEffect(() => {
console.log(store)
console.log(store.actions)
})
this doesn't get re-triggered when the data changes. any idea?
5 Replies
Revxrsal
RevxrsalOP2y ago
i tried using
console.log(store.actions[0])
console.log(store.actions[0])
and
console.log([...store.actions])
console.log([...store.actions])
but it still doesn't get triggered might be useful: instead of modifying an existing element in the array i added items instead using [...prevList, newValue], and that seemed to trigger the effect just fine also tried using a mutable store with createMutable, but modifying an element still didn't seem to work update: for some reason doing this:
setStore(
"actions",
i.index,
block
)
setStore(
"actions",
i.index,
block
)
instead of
setStore(
"actions",
i.index,
"data",
block.data
)
setStore(
"actions",
i.index,
"data",
block.data
)
worked. (block and action are the same type) now, why did that work but setting data only didn't?
Alex Lohr
Alex Lohr2y ago
Fine-grained means that there's no change to actions. You can still track deep changes using our community package @solid-primitives/deep. Another valid option would be to wrap the setter to detect changes.
Revxrsal
RevxrsalOP2y ago
ah i see. so it can't detect things deeper than, say, 2 levels? i thought stores by default react to everything inside them
REEEEE
REEEEE2y ago
it can but you aren't listening for the part that actually changed which is some block data inside of actions Meaning that when you change some block data inside of actions, anything that was listing to actions[0].block.data will react to changes but not anything that was listening to actions
Revxrsal
RevxrsalOP2y ago
Oooh I see now
Want results from more Discord servers?
Add your server