Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140131

Where's the most appropriate place to normalize data?

$
0
0

I am using the JSON API Spec along with the json-api-normalizer package. I'm running into a dilemma when it comes to normalizing single objects with included associations. For instance: I have a single restaurant that has many menus. The only time this becomes a hinderance is when the data is normalized and I need to retrieve the single restaurant that is now nested and can only be retrieved by knowing it's key, which in this case is it's id. This leads me to ask whether I'm normalizing my data in the wrong place. Right now I'm doing it in my reducer on successful retrieval:

case types.FETCH_RESTAURANT_SUCCESS:
  return {
    ...state,
    data: normalize(action.payload, { camelizeKeys: false }),
    error: null, loading: false,
  };

Where and what would be the best way to normalize my data so that I'm not essentially locked out of getting the things I need? Here is the output of the normalized state:

{
  restaurant: {
    data: {
      restaurant: {
        123: {...}
      },
      menus: {
        345: {...},
        678: {...}
      }
    }
  }
}

Viewing all articles
Browse latest Browse all 140131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>