S
SolidJS•6mo ago
Blankeos

DeepTrack for a `Component[]` (Deeptrack for functions)

Hi! Is this possible? Let's say I have:
const L1 = () => {};
const L21 = () => {};
const L22 = () => {};
const L1 = () => {};
const L21 = () => {};
const L22 = () => {};
// Assuming the "LStore" is a createStore
// when it changes to:
const LStore = [L1] // gets triggered.

const LStore = [L1, L21]; // gets triggered.

const LStore = [L1, L22]; // does not seem to get triggered.
// when it changes to:
const LStore = [L1] // gets triggered.

const LStore = [L1, L21]; // gets triggered.

const LStore = [L1, L22]; // does not seem to get triggered.
And I have a deeptrack utility like so:
function deepTrack(store: any) {
for (const k in store) {
const value = store[k];
if (typeof value === "object") {
deepTrack(value);
}
}
}

// On the third change of LStore, it doesn't get triggered.
createEffect(() => {
deepTrack(LStore);
});
function deepTrack(store: any) {
for (const k in store) {
const value = store[k];
if (typeof value === "object") {
deepTrack(value);
}
}
}

// On the third change of LStore, it doesn't get triggered.
createEffect(() => {
deepTrack(LStore);
});
5 Replies
Blankeos
BlankeosOP•6mo ago
Nevermind. It kinda works. No idea what happened. Okay, it's back again. there definitely is an issue when you do reconcile for an Array of functions. Any suggested workarounds for this'?\
bigmistqke
bigmistqke•6mo ago
it's handy for this type of stuff to have a reproduction in the https://playground.solidjs.com/
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Blankeos
BlankeosOP•6mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
halu
halu•6mo ago
are you trying to use a function as an object? idk why else you'd want deep reactivity on a raw function wrapped in an array it works as expected i believe? https://playground.solidjs.com/anonymous/3917c01c-1670-4e53-9341-e10ebbc79540 https://playground.solidjs.com/anonymous/ccf6e719-b81a-46fa-8255-e980be841dbb otherwise, shallow: https://playground.solidjs.com/anonymous/4a71a4ac-f5c4-4388-b057-6e0dbfc49242 Reconcile on array works too: https://playground.solidjs.com/anonymous/15b6ea3c-a814-4e14-9b16-e9456732e351
bigmistqke
bigmistqke•6mo ago
no problem at all! just makes it easier to discuss 🙂 sorry for the radiosilence, was afk It's an unorthodox use of createStore. afaik createStore only works with arrays and objects, not set/map/functions. like halu mentioned above
Want results from more Discord servers?
Add your server