Normalizr + Redux - updating the property of one object

I am creating a music player application and I am using REST API to fetch tracks from different endpoints (playlists, tracks posted by a specific user, etc.).

I am using redux and normalizr to manage my state. I have created an object tracks

that I use to display the object track

and their ids.

In short, my state looks something like this:

{
  playlists: {
    123: { id: 123, name: 'foo', tracks: [1, 2, 3] }
  },
  users: {
    me: { name: 'Niek', tracks: [2, 3] },
  },
  entities: {
    tracks: {
      1: { name: 'bar', user_favorited: false, ... },
      2: { name: 'foo', user_favorited: false, ... },
      3: { name: 'bar', user_favorited: true, ... }
    }
  }
}

      

This works great for me so far. But now I am creating functionality to toggle favorite

track state by calling another API endpoint.

This endpoint does not include the entire resource track

in the response, but I want to update the property of user_favorited

one object track

after a successful API call.

What would be the best way to achieve this?

As a workaround, I am now getting the complete object track

again from a different endpoint after the call to the endpoint completes successfully user_favorited

, but I was hoping to find an elegant solution where this is not needed.

+3
reactjs redux normalizr


source to share


No one has answered this question yet

Check out similar questions:

1126
Why use Redux over Facebook Flux?
804
How do I dispatch a Redux action with a timeout?
567
Why would we use async thread middleware in Redux?
4
Relx reduction reaction action
3
Redux and Normalizr put a single object into an array
2
React + Redux + normalizr api error handling request
2
How to handle entitiy relationship without bidirectional links in normalizr
1
Using reducex-thunk and normalizr to create data objects from multiple API calls
0
Lazy link loading from normalized Redux store
0
Time range based data modeling using redux / normalizr



All Articles
Loading...
X
Show
Funny
Dev
Pics