mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(common): delete unused code for HttpResource (#60919)
Remove the code related to exposing the response of an HTTP request as a `Resource` itself, as the final API will not go in this direction. PR Close #60919
This commit is contained in:
parent
57794f0256
commit
b1bfb214ef
1 changed files with 0 additions and 45 deletions
|
|
@ -381,48 +381,3 @@ class HttpResourceImpl<T>
|
|||
// This is a type only override of the method
|
||||
declare hasValue: () => this is HttpResourceRef<Exclude<T, undefined>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A `Resource` of the `HttpResponse` meant for use in `HttpResource` if we decide to go this route.
|
||||
*
|
||||
* TODO(alxhub): delete this if we decide we don't want it.
|
||||
*/
|
||||
class HttpResponseResource implements Resource<HttpResponseBase | undefined> {
|
||||
readonly status: Signal<ResourceStatus>;
|
||||
readonly value: WritableSignal<HttpResponseBase | undefined>;
|
||||
readonly error: Signal<unknown>;
|
||||
readonly isLoading: Signal<boolean>;
|
||||
|
||||
constructor(
|
||||
private parent: Resource<unknown>,
|
||||
request: Signal<unknown>,
|
||||
) {
|
||||
this.status = computed(() => {
|
||||
// There are two kinds of errors which can occur in an HTTP request: HTTP errors or normal JS
|
||||
// errors. Since we have a response for HTTP errors, we report `Resolved` status even if the
|
||||
// overall request is considered to be in an Error state.
|
||||
if (parent.status() === ResourceStatus.Error) {
|
||||
return this.value() !== undefined ? ResourceStatus.Resolved : ResourceStatus.Error;
|
||||
}
|
||||
return parent.status();
|
||||
});
|
||||
this.error = computed(() => {
|
||||
// Filter out HTTP errors.
|
||||
return this.value() === undefined ? parent.error() : undefined;
|
||||
});
|
||||
this.value = linkedSignal({
|
||||
source: request,
|
||||
computation: () => undefined as HttpResponseBase | undefined,
|
||||
});
|
||||
this.isLoading = parent.isLoading;
|
||||
}
|
||||
|
||||
hasValue(): this is Resource<HttpResponseBase> {
|
||||
return this.value() !== undefined;
|
||||
}
|
||||
|
||||
reload(): boolean {
|
||||
// TODO: should you be able to reload this way?
|
||||
return this.parent.reload();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue