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 option to addEntity #4721

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dimavasylyna
Copy link

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 # (No specific issue linked; this is a general enhancement based on potential community needs.)

What is the new behavior?

This PR adds an optional prepend?: boolean parameter to the addEntity function. When prepend: true is specified, the new entity is inserted at the beginning of the entities array instead of being appended to the end. If prepend is omitted or set to false, the existing behavior (appending to the end) is preserved.

Example

// Add entity to the beginning
patchState(store, addEntity(user1, { prepend: true }));
// Result: entities = [user1, ...existingEntities]

// Add entity to the end (default)
patchState(store, addEntity(user2));
// Result: entities = [...existingEntities, user2]

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Copy link

netlify bot commented Mar 17, 2025

Deploy Preview for ngrx-io ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f03a19b
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/67d82bd1aa4ffb00082e7ffc
😎 Deploy Preview https://deploy-preview-4721--ngrx-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@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
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!

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.

2 participants