How to hide many-to-many relationships in Redux state with Normalization?

Scenario

We have a database that displays the following ratio:

  • A taghas a lotcampaigns
  • A campaignhas a lottags
  • The relationship between campaignsand tagsis represented by an associative entity calledcampaign_tag
  • The object campaign_taghas an attribute.priority

Question

How can we implement normalizr (or any similar library) to create a smooth state of an application that takes into account our associative objects when our associative objects do not have unique identifiers / values?

Notes / Miscellaneous Thoughts

, , , " " " ". , :

{
  entities: {
    campaigns: {
      '1': { id: 1, name: 'Ace', tags: [1, 2, 3] },
      ...
    },
    tags: {
      '1': { id: 1, name: 'Example Tag', campaigns: [1, 2, 3] },
      ...
    }
  },
  ...
}

entities? ? . ?

, .

+4
1

:

  • API: :

    campaigns: [{
      id: <id>,
      name: <name>,
    }],
    tags: [{ id: <id>, name: <name> }],
    campaign_tags: [{campaign_id, tag_id, priority}]
    

    , . redux, , , .

  • API. , , - .

+1

Source: https://habr.com/ru/post/1648589/


All Articles