Detect which dependency changed when using "on" utility with createEffect

Hi, I have the code below:
createEffect(
on(
() => {
triggerFields.forEach((_trigger) => dataStore[_trigger]);
},
() => {
console.log("EFFECT CALLED");
// print the name of the triggerField or property
// of dataStore which changed and caused this effect to run
},
{ defer: true }
)
);
createEffect(
on(
() => {
triggerFields.forEach((_trigger) => dataStore[_trigger]);
},
() => {
console.log("EFFECT CALLED");
// print the name of the triggerField or property
// of dataStore which changed and caused this effect to run
},
{ defer: true }
)
);
I have a store called dataStore which is an object with 50+ properties. I have a string array called triggerFields which correspond to the property names in dataStore. I want this effect to only run when the trigger fields change. So far I have managed to get this to work by simple accessing the particular properties (i.e the string values in TriggerFields) of dataStore. However now inside my effect, I actually want to figure out which of my triggerField was responsible for the effect to run. Any ideas on how I can accomplish this?
2 Replies
TicTacMan
TicTacManOP16mo ago
Extra question, is there any better way for me to track only particular properties of a store? I feel like what im doing here:
triggerFields.forEach((_trigger) => dataStore[_trigger]);
triggerFields.forEach((_trigger) => dataStore[_trigger]);
Might not be the best way to do it
REEEEE
REEEEE16mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
Want results from more Discord servers?
Add your server