Skip to content

Allow rxResource's request fn to handle Observable triggers #58854

@markostanimirovic

Description

@markostanimirovic

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Currently, rxResource's request function doesn't support returning an Observable that can trigger the loader function when new values are emitted.

Workaround:

const dataService = inject(DataService);
const click$ = new Subject<MouseEvent>();
const click = toSignal(click$, { initialValue: null });
const data = rxResource({
  request: click,
  loader: ({ request }) =>
    request ? dataService.getData() : of(null),
});

Proposed solution

Allow request to return an Observable, where each emission triggers the loader function:

const dataService = inject(DataService);
const click$ = new Subject<MouseEvent>();
const data = rxResource({
  request: () => click$,
  loader: () => dataService.getData(),
});

Benefits:

  • More reactive control over loader triggers
  • Better integration with event-based workflows
  • Reduced boilerplate when working with Observables

Alternatives considered

_

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimecore: reactivityWork related to fine-grained reactivity in the core frameworkcross-cutting: signals

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions