File tree Expand file tree Collapse file tree 3 files changed +25
-11
lines changed
Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -1610,7 +1610,6 @@ export interface Resource<T> {
16101610 readonly error: Signal <unknown >;
16111611 hasValue(): this is Resource <Exclude <T , undefined >>;
16121612 readonly isLoading: Signal <boolean >;
1613- reload(): boolean ;
16141613 readonly status: Signal <ResourceStatus >;
16151614 readonly value: Signal <T >;
16161615}
@@ -2022,6 +2021,7 @@ export interface WritableResource<T> extends Resource<T> {
20222021 asReadonly(): Resource <T >;
20232022 // (undocumented)
20242023 hasValue(): this is WritableResource <Exclude <T , undefined >>;
2024+ reload(): boolean ;
20252025 set(value : T ): void ;
20262026 update(updater : (value : T ) => T ): void ;
20272027 // (undocumented)
Original file line number Diff line number Diff line change @@ -289,4 +289,18 @@ describe('httpResource', () => {
289289 await TestBed . inject ( ApplicationRef ) . whenStable ( ) ;
290290 expect ( res . value ( ) ) . toBe ( buffer ) ;
291291 } ) ;
292+
293+ it ( 'should send request on reload' , async ( ) => {
294+ const backend = TestBed . inject ( HttpTestingController ) ;
295+ const res = httpResource ( ( ) => '/data' , { injector : TestBed . inject ( Injector ) } ) ;
296+ TestBed . tick ( ) ;
297+ let req = backend . expectOne ( '/data' ) ;
298+ req . flush ( [ ] ) ;
299+ await TestBed . inject ( ApplicationRef ) . whenStable ( ) ;
300+
301+ res . reload ( ) ;
302+ TestBed . tick ( ) ;
303+ req = backend . expectOne ( '/data' ) ;
304+ req . flush ( [ ] ) ;
305+ } ) ;
292306} ) ;
Original file line number Diff line number Diff line change @@ -72,16 +72,6 @@ export interface Resource<T> {
7272 * This function is reactive.
7373 */
7474 hasValue ( ) : this is Resource < Exclude < T , undefined > > ;
75-
76- /**
77- * Instructs the resource to re-load any asynchronous dependency it may have.
78- *
79- * Note that the resource will not enter its reloading state until the actual backend request is
80- * made.
81- *
82- * @returns true if a reload was initiated, false if a reload was unnecessary or unsupported
83- */
84- reload ( ) : boolean ;
8575}
8676
8777/**
@@ -105,6 +95,16 @@ export interface WritableResource<T> extends Resource<T> {
10595 */
10696 update ( updater : ( value : T ) => T ) : void ;
10797 asReadonly ( ) : Resource < T > ;
98+
99+ /**
100+ * Instructs the resource to re-load any asynchronous dependency it may have.
101+ *
102+ * Note that the resource will not enter its reloading state until the actual backend request is
103+ * made.
104+ *
105+ * @returns true if a reload was initiated, false if a reload was unnecessary or unsupported
106+ */
107+ reload ( ) : boolean ;
108108}
109109
110110/**
You can’t perform that action at this time.
0 commit comments