globalbrain / sefirot

Global Brain Design System.
https://sefirot.globalbrains.com
MIT License
151 stars 12 forks source link

feat(api): allow executing queries without assigning result to data #519

Closed brc-dd closed 3 months ago

brc-dd commented 3 months ago

Adds assign option to useQuery.execute. It's helpful while implementing functionality like "load more".

When assign is false, loading.value will not be set to true before fetching - this is to avoid showing spinner - and calling execute won't update query.data - one would need to manually merge the returned data with existing one.

Example:

const query = useQuery(...)

async function loadMore(): Promise<void> {
    const res = await query.execute({ assign: false })
    ;(query.data.value ??= {}).push(...res)
  }
}
netlify[bot] commented 3 months ago

Deploy Preview for sefirot-story ready!

Name Link
Latest commit 0ed6c4fb3ba5f5be223347ae8fd808762d9dda01
Latest deploy log https://app.netlify.com/sites/sefirot-story/deploys/66261200f61f290008cb61a9
Deploy Preview https://deploy-preview-519--sefirot-story.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 3 months ago

Deploy Preview for sefirot-docs ready!

Name Link
Latest commit 0ed6c4fb3ba5f5be223347ae8fd808762d9dda01
Latest deploy log https://app.netlify.com/sites/sefirot-docs/deploys/66261200607b940008b98c86
Deploy Preview https://deploy-preview-519--sefirot-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

brc-dd commented 3 months ago

When assign is false, loading.value will not be set to true before fetching - this is to avoid showing spinner

This can be split to separate option like silent too for better customization 👀 I don't have any use-case for that though.

kiaking commented 3 months ago

@brc-dd

This can be split to separate option like silent too for better customization 👀 I don't have any use-case for that though.

Good point. Now that I think of, maybe it should make loading to true even though assign is false. Because, we might wanna show loading state while it is calling API 🤔

So yeah, I guess splitting the API to { assign?: boolean, silent?: boolean } does make sense 👀

brc-dd commented 3 months ago

updated