yury-dymov / json-api-normalizer

Normalize JSON API data for redux applications
MIT License
576 stars 40 forks source link

Override meta data from endpoint based on unique ID or path? #60

Closed laila-vinson closed 5 years ago

laila-vinson commented 5 years ago

First of all, thanks for a great and easy to use library.

I'm having some trouble using the meta from an API endpoint to order an array. I have an ordered array returned from a particular API endpoint, which I'm saving the metadata in data -> meta -> (endpoint)

If I make a call that returns four unique values, I get the order saved in data -> meta -> (endpoint) as expected, and the items themselves are saved as a list in the rest of the redux store ("q" in this example).

Pat2

This works great. However, when I make the same call later on, I want to remove one item from the list based on the API response. The API call only returns 3 items in this next response, the ones starting with ID d4208..., 07988..., and e8368...

Part2

The one starting with 31ad7.. is correctly gone from the meta, but e8368... is there twice now.

I'm writing to the store with something like this: return Object.assign({}, normalize(res.data, { endpoint }));. Screenshots are from Redux Devtools Chrome Extension with irrelevant parts blacked out

Is this expected? I'd like to override the meta from each API path if possible. The API calls are the same exact path in both screenshots (including the blacked out part).

Please let me know if more info is needed and thanks again!

laila-vinson commented 5 years ago

Nevermind. I was following this example, which merges everything. Was incorrectly expecting this library to override meta endpoints based on responses (which kind of seems useful for ordering).

Thanks again!