- Notifications
You must be signed in to change notification settings - Fork26.7k
Description
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
When using the new experimentalresource
, whenever the params changed, value of the resource is cleared and reloaded. There is currently no built in mechanism to provide a custom equals function to check if the new params are equal to the previous one, thus allowing unnecessary reload.
Currently, a workaround requires creating a computed signal with the custom equals function, and using its value as params.
Proposed solution
AparamsEqual
field inresources option for a custom equality function to compare params value. Clear existing value and reloadonly when the equality function indicates that params have changed.
const userResource = resource({ params: () => ({/* some complex params */}), paramsEqual: (prev, curr) => /* custom equality checks */, loader: ({params}) => fetchUser(params),});
Also, clarify indocumentation that the value will benull
(orundefined
?) after a new params provided, and before the new value is loaded.
Alternatives considered
Update documentation to emphasis that a computed signal (with custom equal) can also be provided as a params. But this is less intuitive as users expect resources to have similar syntax as other signals, instead of nesting other signals inline. And I don't think this is intended usage anyway.
const userResource = resource({ params: computed(() => ({/* some complex params */}), {equal: customEqualFn}), loader: ({params}) => fetchUser(params),});