Skip to content

Instantly share code, notes, and snippets.

@thehydroimpulse
Last active August 29, 2015 14:20
Show Gist options
  • Save thehydroimpulse/b54ef7da49e801aaf0cc to your computer and use it in GitHub Desktop.
Save thehydroimpulse/b54ef7da49e801aaf0cc to your computer and use it in GitHub Desktop.
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