mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00: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:
parent
5762c23a77
commit
07811ddd7d
3 changed files with 25 additions and 11 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue