Hi Paul,
It seems like you have the right idea here, passing the data object through. The need to transform fields of the data object, which themselves might be promises, makes it a bit trickier, but still doable. Here are a few thoughts:
You don't need to lift functions you pass to when.map. when.map will manage the promises for you and ensure that it only passes fulfilled values to your mapping function.
One approach might be to simply assign the returned promise to data.bodies, and later use the version of all() in when/keys to wait for all the fields of data to fulfill. Here's a modified version of part of your example that shows how you might do it:
var keys = require('when/keys');
function mergeTemplates(data) {
data.bodies = when.map(data.bodies, _.template);
return data;
}
//... modify data or other properties of data as needed
//.. and finally:
when_pipe(tasks, data)
.then(keys.all)
.then(function(data) {
// data's fields are all fulfilled here
// do stuff with data.bodies
});
Hope that helps!