Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

How to work with current entity changes when working with @ngrx/store and @ngrx/entity?

+2
−0

I am fairly new to working with @ngrx pattern in Angular which is a state management pattern relying on Reactive Extensions.

One of the convenient structures is @ngrx/entity which helps with managing record collections.

One typical scenario in the application is to access of list of Foos and enter a Foo to edit its content. I have managed the list store (some sort of Redux store) slice with @ngrx/entity, but also used the same pattern for managing the list of full items (as opposed to the list items which are more lightweight).

This means that @ngrx/entity helps with adding new items, removing them and automatically caching everything related to them.

One advantage is that if reenter the same entity and the server is not available, I still get the old data (as opposed to delivering nothing to the user).

One downside is that all reducer functions must operate on the "big" list (list of full entities). A typical reducer function would look like the following:

mutableOn(SomeFooAction, (state, action) => {
	const toUpdate = state.entities[action.payload.id];

    // do some operations with the entity list to be updated

	return state;
}),

mutableOn is just a replacement of on that allows working in a mutable way with the state, thus reducing the code required to get a new state (otherwise a lot of deep cloning might be required).

One alternative I am thinking of is to not use the @ngrx/entity list adapter anymore and simply allow a single entity (currentFoo) to be managed when in edit view.

I am wondering how is this typically handled in web applications relying on a Redux like pattern.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

0 answers

Sign up to answer this question »