Last active
August 29, 2015 14:20
-
-
Save thehydroimpulse/b54ef7da49e801aaf0cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import serialize from 'stacks/serialize'; | |
import Team from 'stacks/model/team'; | |
let user = serialize('user') | |
// We want to expose the key `token` under the key `id`, replacing | |
// whatever `id` used to be. | |
.map('token', 'id') | |
// A promise mapping, allowing us to take a single | |
// key and returning a promise. The resolved value | |
// must be of the format: | |
// | |
// `{ key: String, value: Any }` | |
.mapPromise('team_id', id => { | |
return Team.forge({ id: id }) | |
.fetch() | |
.then(team => { | |
// If we don't have a team, return a nullified key named `team`. | |
if (!team) { | |
return { key: 'team', value: null } | |
} | |
return { key: 'team', value: team.get('token') }; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment