-
-
Save idream3/dceec5e8bf4021329b20 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
/* | |
Extracting Maps completely out of the state tree and defining below. | |
Also, flattening the entire tree. | |
Con: No way to tell what is a Map or not | |
*/ | |
var state = { | |
// application data | |
data: { | |
users: {}, | |
projects: {}, | |
license: {}, | |
locations: {}, | |
locationSchedules: {}, | |
locationServices: {}, | |
crawlers: {} | |
concepts: {}, | |
conceptRules: {}, | |
conceptRuleParameters: {}, | |
reports: { | |
// much more data | |
} | |
}, | |
view: { | |
currentUserId: null, | |
selectedLocationId: null, | |
locationSortType: 'ASC', | |
locationSortBy: 'status', | |
selectedConceptId: null, | |
conceptSortType: 'DESC', | |
conceptSortBy: 'name' | |
} | |
} | |
Cerebral.map('view.selectedUser', | |
['data.users', 'view.selectedUserId'], | |
(Cerebral, state) => { | |
return state.users[state.selectedUserId] | |
}) | |
Cerebral.map('view.selectedLocation', | |
['view.selectedLocationId', 'data.locations'], | |
(Cerebral, state) => { | |
let location = state.locations[state.selectedLocationId].toJS(); // so we can mutate | |
let schedules = Cerebral.get('data.locationSchedules'); | |
// grab echedules and attach to location object | |
location.schedules = location.scheduleIds.filter(id => { | |
return schedules[id] | |
}) | |
return location | |
}) | |
Cerebral.map('view.sortedLocations', | |
['view.locationSortType', 'view.locationSortBy', 'data.locations'], | |
(Cerebral, state) => { | |
return Object.keys(state.locations).map(id => { | |
return state.locations[id] | |
}).sort(/* sort function */) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment