-
-
Notifications
You must be signed in to change notification settings - Fork 343
Add loaded prop to subscription state #1314
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
Comments
Mmh, normally pending serves that purpose. For arrays you might need the wait prop set to true |
I'm willing to investigate and try and make a PR for this. Would ensuring the |
pending wasn't set as it should. It should now be fixed |
Awesome! I might try to help write some additional documentation around the subscription state to explain the use cases for using |
I just tried the update (release <p v-if="!pending && items.length === 0">No items yet</p> |
What problem is this solving
On my index page, I have a "no items" message that is supposed to be displayed if there are no items in the collection.
The following naïve approach will briefly flash the message even if there are items in the collection because useCollection starts with an empty array before populating it.
I then found the subscription state in the docs, which has a
pending
reactive value. However, the following still flashes the message sincepending
seems to change before the collection has fully loaded.So I finally wound up using the
promise
from the subscription state. While this worked, it was very awkward to integrate reactively.Proposed solution
I propose introducing a dedicated
loaded
prop to the subscription state. It would be a reactive boolean that only togglestrue
when the data is initially loaded. This is similar to the VueApollo loading state except there it's aloading
prop that toggles each time new data is loaded.My current workaround looks like
And I use
useCol()
wherever I'd normally useuseCollection()
.Describe alternatives you've considered
Another option would be to make
pending
staytrue
until the data had fully loaded. While this technically alters existing API behaviour, it's unclear howpending
is even supposed to be used if it doesn't work like I originally expected it to. Is that a bug?The text was updated successfully, but these errors were encountered: