Skip to content

[Feature Request] enabled option should be reactive by default #4

@ylc395

Description

@ylc395

Now, If we want to update a Query's options, we should wrap the "dynamic options" in an option function like this:

const query = new MobxQuery({
  options: () => ({
    enabled: this.myObservableValue > 10,
  }),
});

Considering enabled is one of the mostly used options, we can make it reactive by default like:

const query = new MobxQuery({
    enabled: () => this.myObservableValue > 10,  //  which is a shortcut for `computed(() => this.myObservableValue > 10)`,
});

And queryFn should be able to be a computed too. like this:

const id = observable.box(null);

new MobxQuery({
    queryFn: computed(() => id.get() ? axios.get(`/api/id/${id.get()}`) : skipToken), // is a shortcut for `{ options: () => ({ queryFn: id.get() ? axios.get('/api/id/${id.get()}') : skipToken })}`, which is not supported now, too
})

All these cases can be found in official vue adapter document(considering vue-reactivity and mobx is almost the same thing, this library and official vue adaptor can share the same use cases and API design and even implementation):
https://tanstack.com/query/v5/docs/framework/vue/guides/disabling-queries

If you think these proposals are acceptable, I can submit a PR maybe this weekend?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions