I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[x] Support request
[ ] Other... Please describe:
I have a simple entity store in which I store team members. When a user enters the app I fetch it's data (via the team-members store, as the user also is a team member). When the user goes to /team I want to fetch all the team members, but for performance reason I only fetch fewer properties, compared to fetching the individual user. I need all the user's data at any time, in order to display links in the navbar properly.
So the desired behaviour would be to add any team members, that weren't fetched before, to update the ones that were already fetched and to remove the ones that aren't part of the newly fetched team members. I know the function upsert handles the first two points, but is there any other built-in function that can perform my desired task?
If there is no built-in function, a function like 'upset' (Removing any entities, that are not part of the new entities, and updating the old ones), implementing such a function would provide one further functionality for the community.
Hi @Tobjoern 馃檪
Sounds to me like you can get the functionality you describe as 'upset' by using the remove method and giving it a function as a parameter, which returns true if the entity in the store isn't one of the newly fetched team members, e.g. store.remove((entity) => !newTeamMembers.some((newMember) => newMember.id === entity.id));
@Tobjoern as @theblushingcrow suggested you can do it by using upsert and remove with predicate function:
@transaction
updateStore() {
store.upsert(...);
store.remove((entity) => ...);
}
Sounds good?
Thanks for the quick help! This is exactly what I was looking for :)