ngneat / query

🚀 Powerful asynchronous state management, server-state utilities and data fetching for Angular Applications
https://ngneat.github.io/query
569 stars 39 forks source link

Feature Request: Enhance `injectQuery` to Accept an Options Object #197

Open jon9090 opened 3 months ago

jon9090 commented 3 months ago

Which @ngneat/query-* package(s) are relevant/releated to the feature request?

query

Description

Description

Currently, the injectQuery function does not accept an options object directly. This feature would enhance the usability and flexibility of the function, making it more intuitive and powerful for developers.

Current Implementation

class MyComponent {
  #query = injectQuery();

  getTodos() {
    return this.#query({
      queryKey: ['todos'] as const,
      queryFn: () => {
        return this.#http.get<Todo[]>('https://jsonplaceholder.typicode.com/todos');
      },
    });
  }
}

Proposed Change

Modify the injectQuery function to accept an options object, allowing for more streamlined and readable code. The new usage would be similar to this:

import { injectQuery } from '@tanstack/angular-query-experimental';
...
class MyComponent {
  #query = injectQuery({
    queryKey: ['todos'] as const,
    queryFn: () => {
        return this.#http.get<Todo[]>('https://jsonplaceholder.typicode.com/todos');
    },
   });
  }
}

Benefits

  1. Consistency: Aligns with other common practices of passing an options object in similar libraries.
  2. Readability: Enhances code readability and maintainability.
  3. Flexibility: Allows for easier configuration and extension of queries.

Thank you for considering this enhancement!

wizardnet972 commented 1 month ago

I love this feature idea!
@NetanelBasal, @luii, would you like me to submit a PR?