Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(signals): add prepend entity updaters #4721

Merged
merged 4 commits into from
Mar 28, 2025

Conversation

dimavasylyna
Copy link
Contributor

@dimavasylyna dimavasylyna commented Mar 17, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

The addEntity function in @ngrx/signals currently appends new entities to the end of the entities array by default. There is no way to control the insertion order, limiting flexibility in scenarios where entities need to be added at the beginning (e.g., for "most recent first" displays).

Closes #4723

What is the new behavior?

This PR adds new prependEntity and prependEntities entity updaters for adding entities to the beginning of the collection.

Example

patchState(store, prependEntity(user1));
// Result: entities = [user1, ...existingEntities]

patchState(store, prependEntites([user1, user2]));
// Result: entities = [user1, user2, ...existingEntities]

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Copy link

netlify bot commented Mar 17, 2025

Deploy Preview for ngrx-io canceled.

Name Link
🔨 Latest commit f018310
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/67e6eb7d1b141c0008048dc9

@markostanimirovic
Copy link
Member

Hi @dimavasylyna,

Can you open a new GitHub issue (feature request) for this feature? Based on the community feedback, we'll decide if this feature should land and how it should be designed. You can find more info on this topic in our contribution guidelines: https://github.com/ngrx/platform/blob/main/CONTRIBUTING.md#submitting-new-features

@dimavasylyna
Copy link
Contributor Author

Hi @markostanimirovic,
Thanks for the feedback! I’ve opened a new feature request as an RFC issue per the contribution guidelines. You can find it here: RFC: Add prepend option to addEntity in @ngrx/signals/entities #4723. Looking forward to community input on this!

@dimavasylyna dimavasylyna force-pushed the feat/add-entity-prepend branch from eea6adc to 8b110e5 Compare March 25, 2025 12:06
@dimavasylyna dimavasylyna changed the title feat(signals): add prepend option to addEntity feat(signals): add prepend entity updaters Mar 25, 2025
Copy link
Member

@markostanimirovic markostanimirovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @dimavasylyna! I left a few suggestions:

@dimavasylyna dimavasylyna force-pushed the feat/add-entity-prepend branch from be42877 to 9ece0a7 Compare March 26, 2025 15:00
Copy link
Member

@markostanimirovic markostanimirovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👌

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small nits

@timdeschryver timdeschryver merged commit dac8665 into ngrx:main Mar 28, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Add prepend option to addEntity in @ngrx/signals/entities
3 participants