javascript - How do I structure my store for a master-detail view in redux? -


i'm building email inbox using redux. 1 half of screen has list of email subjects, , can click 1 view full email contents on other half of screen. devs call "master-detail" type application.

an email displayed in "master" list (it's class in app called simpleemail) looks this. model has been shrunken down reduce amount of data transmitted when fetching list of possibly 100+ emails.

{   from: "hello@site.com",   subject: "hello, jon",   id: "abc123" } 

an email in "detail" list (a class called emaildetails) has model way more complicated , has different shape.

{   id: "abc123"   headers: {     from: "hello@site.com",     subject: "hello, jon",     to: [],     bcc: null,     cc: null,     replyto: // , 10 more fields   },  bodyhtml: "this text",   attachments: [],   receivedat: null,   // , 10 other fields } 

how should shape application state in redux handle these 2 different models being used? initial thought following:

{    emailmaster: {      entitiesbyid: {},  // map of emails keyed id      ids: [],      selectedid: null      isfetching: false,      iserror: false    },    emaildetails: {     selectedentity: {},   // single email object     isfetching: false,     iserror: false    } } 

i can see couple issues design:

  • the data not normalized, , thus, there duplicate data. violates major design principle of redux.
  • if user updates email (such marking unread), have check see if email loaded in "detail" view, , update second model. seems code smell.
  • there no single source of truth email id selected. if there race condition (maybe user clicking around screen fast) , emailmaster.selectedid different value emaildetails.selectedentity.id? again, seems code smell.

something doesn't feel right. there better way go designing shape of application state?


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -