-
-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: bindFirestoreRef not reacting to getter #1496
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the test: rather than using a ref of a collection, put a string in the ref and use () => collection(db, '...', myRef.value)
Could you also add the same for |
I returned the I wrote a test for I was able to add a test for The current implementation uses an named collection ( Should I use Something like: it('can be bound to a getter', async () => {
const parentCollectionName = collection().path.split('/').at(-1);
const populatedCollection = collection<{ name: string }>(
parentCollectionName,
'parentDocument',
'populatedCollection'
);
const collectionName = ref('populatedCollection');
const { wrapper, promise } = factory({
ref: () =>
collection(parentCollectionName, 'parentDocument', collectionName.value),
});
await promise.value;
await addDoc(populatedCollection, { name: 'a' });
await addDoc(populatedCollection, { name: 'b' });
expect(wrapper.vm.list).toHaveLength(2);
expect(wrapper.vm.list).toContainEqual({ name: 'a' });
expect(wrapper.vm.list).toContainEqual({ name: 'b' });
collectionName.value = 'emptyCollection';
await nextTick();
await promise.value;
await nextTick();
expect(wrapper.vm.list).toHaveLength(0);
});
|
It should be fine the way you did it it, no need to create a subcollection 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
I published a patch 👍 |
Closes #1495
Checking if the
docOrCollectionRef
is a ref before setting up a watch to re-bind the firestore meant getters weren't being watched.Using
watch(() => toValue(docOrCollectionRef), bindFirestoreRef)
will keep the old behaviour of tracking refs and computeds while also tracking getters.In this case, we also don't need to check what
docOrCollectionRef
is.Unless there is a cost in watching an non-reactive source (I don't think so, but I'm not sure).
I'm still learning my way around the tests, I tried the following, but the tests hangs and fails:
But I must be doing something wrong because even when I use
ref: listRef
it also fails, butref: listCollectionRef
it works.I'll keep the PR as a draft while I work on those tests.