Skip to content

Instantly share code, notes, and snippets.

@raycmorgan
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raycmorgan/8808531 to your computer and use it in GitHub Desktop.
Save raycmorgan/8808531 to your computer and use it in GitHub Desktop.
var rj = require('rj');
// item.js
exports['1.2.0'] = {
$defaultFields: ['id', 'live', 'createdAt', 'owner'],
$select: [{_id: 'id'}, 'live'],
createdAt: function (item) {
return item.createdAt.getTime();
}
owner: rj.child('user'),
// watchers: rj.child('user', 'watchers')
watchers: rj.child('user', collectWatchers)
}
function collectWatchers(item, opts) {
var watchers = _.map(item.watchers, function (watcherId) {
return _.grab(opts.watchers, {_id: watcherId});
});
return watchers.length ? watchers : undefined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment