-
-
Save idream3/f7b476671f25a116c584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Most liked approach because Maps are defined within the data structure for clarity, but details abstracted out. | |
Example of only `some` of the various Maps needed for the tree. You can see how these can pile up quickly. | |
*/ | |
var state = { | |
// application data | |
data: {}, | |
// I like declaring the Maps in the same space as the other data | |
// but maybe not defining the function to reduce clutter. | |
view: { | |
// possibly inline because simple | |
locationServicesOnline: ['data.locationServices', (Cerebral, state) => { state.locationServices.online }], | |
locationServicesOffline: Map.locationServicesOffline, | |
projectRunning: Map.projectRunning, | |
projectTransitioning: Map.projectTransitioning, | |
currentUserId: null, | |
selectedUser: Map.selectedUser, | |
sortedUsers: Map.sortedUsers, | |
pendingUsers: Map.pendingUsers, | |
selectedLocationId: null, | |
selectedLocation: Map.selectedLocation, | |
sortedLocations: Map.sortedLocations, | |
disabledLocations: Map.disabledLocations | |
locationSortType: 'ASC', | |
locationSortBy: 'status', | |
selectedConceptId: null, | |
conceptSortType: 'DESC', | |
conceptSortBy: 'name' | |
} | |
} | |
// since you can't have functions on the tree, we can check for | |
// function definitiona and convert the return value to Cerebral.Map automatically. | |
var Map = { | |
locationServicesOffline() { | |
return ['data.locationServices', (Cerebral, state) => { !state.locationServices.online }] | |
} | |
selectedUser() { | |
return ['data.users', 'view.selectedUserId', | |
(Cerebral, state) => { | |
return state.users[state.selectedUserId] | |
}] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment