mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(core): move reload method from Resource to WritableResource (#61441)
Now only mutable resources can be reloaded. PR Close #61441
This commit is contained in:
committed by
Andrew Scott
parent
5762c23a77
commit
07811ddd7d
@@ -1610,7 +1610,6 @@ export interface Resource<T> {
|
||||
readonly error: Signal<unknown>;
|
||||
hasValue(): this is Resource<Exclude<T, undefined>>;
|
||||
readonly isLoading: Signal<boolean>;
|
||||
reload(): boolean;
|
||||
readonly status: Signal<ResourceStatus>;
|
||||
readonly value: Signal<T>;
|
||||
}
|
||||
@@ -2022,6 +2021,7 @@ export interface WritableResource<T> extends Resource<T> {
|
||||
asReadonly(): Resource<T>;
|
||||
// (undocumented)
|
||||
hasValue(): this is WritableResource<Exclude<T, undefined>>;
|
||||
reload(): boolean;
|
||||
set(value: T): void;
|
||||
update(updater: (value: T) => T): void;
|
||||
// (undocumented)
|
||||
|
||||
@@ -289,4 +289,18 @@ describe('httpResource', () => {
|
||||
await TestBed.inject(ApplicationRef).whenStable();
|
||||
expect(res.value()).toBe(buffer);
|
||||
});
|
||||
|
||||
it('should send request on reload', async () => {
|
||||
const backend = TestBed.inject(HttpTestingController);
|
||||
const res = httpResource(() => '/data', {injector: TestBed.inject(Injector)});
|
||||
TestBed.tick();
|
||||
let req = backend.expectOne('/data');
|
||||
req.flush([]);
|
||||
await TestBed.inject(ApplicationRef).whenStable();
|
||||
|
||||
res.reload();
|
||||
TestBed.tick();
|
||||
req = backend.expectOne('/data');
|
||||
req.flush([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,16 +72,6 @@ export interface Resource<T> {
|
||||
* This function is reactive.
|
||||
*/
|
||||
hasValue(): this is Resource<Exclude<T, undefined>>;
|
||||
|
||||
/**
|
||||
* Instructs the resource to re-load any asynchronous dependency it may have.
|
||||
*
|
||||
* Note that the resource will not enter its reloading state until the actual backend request is
|
||||
* made.
|
||||
*
|
||||
* @returns true if a reload was initiated, false if a reload was unnecessary or unsupported
|
||||
*/
|
||||
reload(): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,6 +95,16 @@ export interface WritableResource<T> extends Resource<T> {
|
||||
*/
|
||||
update(updater: (value: T) => T): void;
|
||||
asReadonly(): Resource<T>;
|
||||
|
||||
/**
|
||||
* Instructs the resource to re-load any asynchronous dependency it may have.
|
||||
*
|
||||
* Note that the resource will not enter its reloading state until the actual backend request is
|
||||
* made.
|
||||
*
|
||||
* @returns true if a reload was initiated, false if a reload was unnecessary or unsupported
|
||||
*/
|
||||
reload(): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user