-
-
Save idream3/e426349fd71ebb55f166 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
/* | |
State Exploration 2. | |
Playing with diferent ways to configure Maps. | |
*/ | |
var state = { | |
// application data, changed from `model`. | |
data: { }, | |
// Maps are related to views so It makes some sense to put them | |
// under a view domain. | |
view: { | |
currentUserId: null, | |
// 1. array with function as the last parameter | |
selectedUser: [ | |
'data.users', | |
'view.selectedUserId', | |
(Cerebral, state) => { | |
return state.users[state.selectedUserId] | |
}], | |
// 2. function that returns the above | |
selectedUser: () => { | |
return ['data.users', 'view.selectedUserId', | |
(Cerebral, state) => { | |
return state.users[state.selectedUserId] | |
}] | |
}, | |
// 3. object with path and map keys | |
selectedUser: { | |
path: ['data.users', 'view.selectedUserId'], | |
map: (Cerebral, state) => { | |
return state.users[state.selectedUserId] | |
} | |
} | |
setup: { | |
locations: { | |
selectedLocationId: null, | |
selectedLocation: [ | |
':selectedLocationId', // because of the nesting, the `:` provides a way to point to the current path. | |
'data.locations.locations', | |
(Cerebral, state) => { | |
let location = state.locations[state.selectedLocationId].toJS(); // so we can mutate | |
let schedules = Cerebral.get('data.locations.schedules'); | |
// grab echedules and attach to location object | |
location.schedules = location.scheduleIds.filter(id => { | |
return schedules[id] | |
}) | |
return location | |
}], | |
sortType: 'ASC', | |
sortBy: 'status', | |
sortedLocations: [ | |
':sortType', | |
':sortBy', | |
'data.locations.locations', | |
(Cerebral, state) => { | |
return Object.keys(state.locations).map(id => { | |
return state.locations[id] | |
}).sort(/* sort function */) | |
}] | |
}, | |
concepts: { ... } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment