I'm currently writing my second Qwik app, a calculator, when I encountered this problem and was wondering if this is a good pattern to use or not. I have a well sized object that keeps track of my user input. I need to display that input on the screen whenever it changes.
After refactoring and rethinking my code, I decided that I had to track each of my object's key individually since tracking the object with no named keys did not work .
useTask$(({ track }) => {
// this does not log/track at all
track(() => mathOperation);
console.log("im tracking!!!");
display.value = getDisplayOfMathNode(mathOperation);
});
However, since I did not want to have 5 different tracks all based on the same object, I decided to opt for something I was 90% sure it wasn't going to work:
useTask$(({ track }) => {
// this does log/track :)
track(() => Object.keys(mathOperation));
console.log("im tracking!!!");
display.value = getDisplayOfMathNode(mathOperation);
});
I have rechecked the documentation of both track and useStore and neither mentions this pattern for tracking all of the keys in an object. This seems to me to be a shame because it feels like a very intuitive solution.
If someone more experienced with Qwik could answer this question that would be very helpful since I'm still very early on this project. I also would happily file a PR to update the docs so that they mention this pattern if other (hopefully more experienced) users find it useful too.