JSFiddle - React, Tailwind, and code Playground
by extempl
JavaScript
nonEditorialMethod = function () {
modelName = result.object_type.capitalize + 'Post'
FeaturedItem.app.models[modelName].findById(result.object_id, function (err, instance) {
if (!err && instance) {
od = instance.data || instance;
}
callback();
})
}
editorialMethod = function () {
result.object_id_editorial = result.object_id;
var od = result.object_data = {}
if (!result.editorial)
var editorial = result.editorial = {}
var _asyncCallback = function (type) {
return function (cacheCallback) {
var id = editorial[type + '_id']
if (!id)
return cacheCallback();
_getCache({
name: type,
cache_model: type.capitalize() + 'Cache',
id: id
}, od, cacheCallback)
}
}
// getting film & shorlist details in parallel
async.parallel([
_asyncCallback('shortlist'),
_asyncCallback('film')
], function (err, results) {
// at this point we should have shortlist data - so let's fetch shortlister and editorial ids
// as we can't rely on the ones in db (that is not being updated by cache updater)
var shortlister_id = od.shortlist ? od.shortlist.shortlister_id : null;
var film_id = od.film ? od.film.id : null;
var editorial_id = _getEditorialIdInShortlist(od.shortlist, film_id);
editorial.shortlister_id = shortlister_id;
editorial.editorial_id = editorial_id;
async.parallel([
_asyncCallback('editorial'),
_asyncCallback('shorlister')
], callback)
})
}
switch (result.object_type) {
case 'blog':
case 'film':
case 'shorlist':
case 'shortlister':
nonEditorialMethod()
break;
case 'editorial':
editorialMethod()
break;
default:
callback()
}