Handling data and state?


#1

There seems to be very little guidance on how best to handle state and data in a non-trivial app.

For example, I have a mapping application that will show various locations on a map component that have been loaded from a backend API. These locations are also displayed on a separate component. In other words, I’m sharing data across different parts of my app.

What are the recommended ways to handle state in Ionic/Angular apps? I’ve seen ngrx mentioned a few times and it seems powerful, but it’s not mentioned in either the Angular docs or the Ionic docs.

Are there any recommended approaches by either library, or is ngrx the go-to?


#2

In the very first intro tutorial to Angular:

Services are a great way to share information among classes that don’t know each other.

https://angular.io/tutorial/toh-pt4#why-services

What other guidance would you need and where else would you expect to find it?


#3

Start with:

State:

Some sample ngrx code:

Data:

Like this:

Like this:


#4

Thanks robinyo, those links are very helpful


#5

To follow on, for anyone who comes across this post with the same uncertainty, here are some great blog posts on a sensible “observable data service” pattern that helps manage data in non-trivial application that rely on external data sources: