Skip to content
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

Add clear method to Query #275

Merged
merged 2 commits into from
Sep 23, 2020
Merged

Add clear method to Query #275

merged 2 commits into from
Sep 23, 2020

Conversation

mtsewrs
Copy link
Collaborator

@mtsewrs mtsewrs commented Sep 3, 2020

This is related to the issue #273 which adds a clear method to be able to reset the query to undefined again after fetching.

@mtsewrs mtsewrs added the enhancement New feature or request label Sep 3, 2020
src/Query.ts Outdated
@@ -93,6 +93,12 @@ export class Query<T = unknown> implements PromiseLike<T> {
}
}

clear = (): void => {
Copy link
Collaborator

@chrisdrackett chrisdrackett Sep 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only potential suggestion here is using clearData vs. clear just to make it more clear what you are clearing. clear?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I thought that was clear but we can rename it.

@chrisdrackett
Copy link
Collaborator

@mattiasewers just one comment, but also curious what use case you are hitting with this

@special-character
Copy link
Contributor

special-character commented Sep 3, 2020

@mattiasewers Thanks for the PR. Could you explain a bit about what this is helping you solve? I understand you are clearing the data for the Query but I don't quite understand why you need to do this.

When we use the Query it is typically from the RootStore.base file which creates a new query for every request. Are you re-using the query object somehow?

@mtsewrs
Copy link
Collaborator Author

mtsewrs commented Sep 4, 2020

@chrisdrackett @special-character I'm working on a app for my company where I need to reset the data object without making a another request, I don't know if that is possible currently which is why I made this pr.

@special-character
Copy link
Contributor

@mattiasewers Thanks for commenting, I get that you need to clear the data I was curious about what the use case was and how you were using the Query. I haven't used the data directly from the Query object because it has been more internal for mst-gql (until now). The only case I was thinking of was for clearing the cache for the query the next time it is called with the same args. I always use the data out of the store or use the query options to change how a particular request acts.

Do you need it to clear the cache or is there another use case that you need this for?

@mtsewrs
Copy link
Collaborator Author

mtsewrs commented Sep 5, 2020

@special-character Yes I need to clear the cache but only for that Query object

@mtsewrs mtsewrs linked an issue Sep 7, 2020 that may be closed by this pull request
src/Query.ts Outdated Show resolved Hide resolved
@chrisdrackett chrisdrackett merged commit 4f64042 into mobxjs:main Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a clear or reset function to query
3 participants