Akita: Function that Sets, Updates and Removes

Created on 11 Jun 2019  路  3Comments  路  Source: datorama/akita

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:

Current behavior

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.

Expected behavior

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?

What is the motivation / use case for changing the behavior?

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.

question

All 3 comments

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 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RonnieRocket147 picture RonnieRocket147  路  5Comments

NetanelBasal picture NetanelBasal  路  6Comments

bruceharrison1984 picture bruceharrison1984  路  6Comments

mikejr83 picture mikejr83  路  6Comments

jvitor83 picture jvitor83  路  3Comments