-
Notifications
You must be signed in to change notification settings - Fork 8
Computed value is not recomputed after dependencies change #219
Comments
Thanks for reporting this issue @leopf ;D
I'll dig into your issue this evening and keep you updated. Thanks ;D
|
Thanks for the quick response! I did some digging as well, and it seems like the computed value is updated asynchronously. I added a sideeffect to test this: ...
const selectedUser = createComputed(() => {
return userCollection.getItemValue(selectedUserId.value);
});
selectedUser.addSideEffect("somerandomkey", (instance) => console.log("NEW SELECTED USER:", instance.value), { weight: 0 });
... The new output is the same except after the already posted output it outputs the new value for the computed instance.
This would make sense, since the compute function within the Computed instance is asynchronous. For this to work, it might be necessary to differentiate between async and sync compute functions under the hood. If my suspicion proves correct, I will follow up with a PR. |
Yeah, you are right 👍 See code sandbox: https://codesandbox.io/s/issue-219-ufcck?file=/src/main.js |
fixed in #222 |
🐛 Bug report
I have a problem with not updating computed values. I am using a demo API to download and insert users into a collection. I want to use a computed value to get a user from this collection based on a user id, which is defined in a state. The first compute works with the default user id, but after updating the user id the value is not recomputed. I took a look at the deps prop and found all the necessary observers with the correct values, though the value of the computed user was incorrect.
The first compute only works if I define the computed value after inserting the users into the collection, otherwise this computed value is stuck on undefined.
🤖 Current Behavior
output:
🎯 Expected behavior
I would expect this to work, as defined in the docs.
📄 Reproducible example
I created a simple main.ts file and ran it with ts-node.
💡 Suggested solution(s)
➕ Additional notes
💻 Your environment
The text was updated successfully, but these errors were encountered: