Shape of State - Tuong-Nguyen/JavaScript-Structure GitHub Wiki
Organization
- Organize data within that top-level object
- Each top-level key represents some "domain" or "slice" of related data
{
visibilityFilter: 'SHOW_ALL',
todos: [
{
text: 'Consider using Redux',
completed: true,
},
{
text: 'Keep all state in a single tree',
completed: false
}
]
}
Types of Data
3 categories:
- Domain data: data that the application needs to show, use, or modify (such as "all of the Todos retrieved from the server")
- App state: data that is specific to the application's behavior (such as "Todo #5 is currently selected", or "there is a request in progress to fetch Todos")
- UI state: data that represents how the UI is currently displayed (such as "The EditTodo modal dialog is currently open")
State Shape pattern
{
domainData1 : {},
domainData2 : {},
appState1 : {},
appState2 : {},
ui : {
uiState1 : {},
uiState2 : {},
}
}