Content-Length: 377832 | pFad | https://github.com/angular/angular/commit/90a16a10888eee37d8a61cdbfad070e002a3cfdf

B7 fix(common): support equality function in httpResource (#60026) · angular/angular@90a16a1 · GitHub
Skip to content

Commit 90a16a1

Browse files
cexbrayatAndrewKushnir
authored andcommitted
fix(common): support equality function in httpResource (#60026)
The `equal` option was not passed to the underlying resource. PR Close #60026
1 parent 8d770ec commit 90a16a1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Diff for: packages/common/http/src/resource.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
Resource,
2020
WritableSignal,
2121
ResourceStreamItem,
22+
type ValueEqualityFn,
2223
} from '@angular/core';
2324
import {Subscription} from 'rxjs';
2425

@@ -240,6 +241,7 @@ function makeHttpResourceFn<TRaw>(responseType: 'arraybuffer' | 'blob' | 'json'
240241
() => normalizeRequest(request, responseType),
241242
options?.defaultValue,
242243
options?.parse as (value: unknown) => TResult,
244+
options?.equal as ValueEqualityFn<unknown>,
243245
) as HttpResourceRef<TResult>;
244246
};
245247
}
@@ -313,6 +315,7 @@ class HttpResourceImpl<T>
313315
request: () => HttpRequest<T> | undefined,
314316
defaultValue: T,
315317
parse?: (value: unknown) => T,
318+
equal?: ValueEqualityFn<unknown>,
316319
) {
317320
super(
318321
request,
@@ -364,7 +367,7 @@ class HttpResourceImpl<T>
364367
return promise;
365368
},
366369
defaultValue,
367-
undefined,
370+
equal,
368371
injector,
369372
);
370373
this.client = injector.get(HttpClient);

Diff for: packages/common/http/test/resource_spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,23 @@ describe('httpResource', () => {
165165
expect(res.value()).toEqual('[1,2,3]');
166166
});
167167

168+
it('should allow defining an equality function', async () => {
169+
const backend = TestBed.inject(HttpTestingController);
170+
const res = httpResource<number>('/data', {
171+
injector: TestBed.inject(Injector),
172+
equal: (_a, _b) => true,
173+
});
174+
TestBed.flushEffects();
175+
const req = backend.expectOne('/data');
176+
req.flush(1);
177+
178+
await TestBed.inject(ApplicationRef).whenStable();
179+
expect(res.value()).toEqual(1);
180+
181+
res.value.set(5);
182+
expect(res.value()).toBe(1); // equality blocked writes
183+
});
184+
168185
it('should support text responses', async () => {
169186
const backend = TestBed.inject(HttpTestingController);
170187
const res = httpResource.text(

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/angular/angular/commit/90a16a10888eee37d8a61cdbfad070e002a3cfdf

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy