Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Custom equal function for params in signal resources #64171

Open
Labels
Milestone
@chiwai-g

Description

@chiwai-g

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),});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp