#rxResource: Howto daisy chain dependent calls rxResources

6 messages · Page 1 of 1 (latest)

sinful tusk
#

Hello everyone!

Recently I had the opportunity to develop a small app so I started fresh with the latest Angular version (20) and tried out some features.

Basically I have a list of select boxes which depend on one another. Let's say movie releases, first you select a genre (Horror, SciFi).

When selected, based on the genre the medium are loaded with rxResource (e.g, DVD, BluRay or Amazon Prime, Netflix, etc.).

Then a third and a fourth option is presented (e.g. Year, Month) until finally the selection is narrow enough to display a list of movies.

This was all working until I noticed that by refreshing the browser, the whole selection was gone. So I added routing to my app. Each select box now adds a navigation path when changed.

And now things start falling apart. The main problem is, that after a refresh (F5) all values are immediately available from the router. But the rxResources depend on each other.

So while I have for example the medium (BluRay) from the router, the genres aren't loaded yet. So I basically need a mechanism to chain the rxResources together.

After the genres are loaded and the router contains a media, load all the media and select the media from the router and then to a similar thing with third and fourth option until lastly trigger the loading of the movie list.

Does anybody have suggestions on howto approach such a scenario?

Best regards,
Billie

vital echo
#

Don't you already have that? The media are loaded when the genre changes, so if you set the genre based on the router params, this should work the same way, shouldn't it?
As always, code would help.

vital echo
#

Forms and signals don't fit well together, hence the need for effects and subscriptions to valueChanges, but a new signals form is under development.

sinful tusk
#

Hi @vital echo!

I wasn't expecting you to write code for me, but thank you for your effort. I copied the project to investigate further, since routes don't seem to work well in stackblitz.

I understand how you link the router to the selection but I don't see the part where the router initializes the boxes.

In your example the ActivatedRoute in line #73 is not used. So when I refresh, the route information is reset.

But the goal is sort of a deep link, where opening http://localhost:4200/?genre=comedy&medium=dvd&movie=

Will load the data for genres, select comedy, load medium(s), selected dvd and so on.

vital echo