-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (20 loc) · 804 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
const BB = require('bluebird');
const _ = require('lodash');
module.exports = resPromises;
function resPromises(overrideResRender) {
var renderMethodName = overrideResRender ? 'render' : 'renderAfterPromises';
return function(req, res, next) {
// attach to this object anything you want to wait to render for
res.promises = {};
var render = res.render;
res[renderMethodName] = function(template, viewModel) {
// wait for all promises attached to resolve before calling render with resolutions
BB.props(res.promises)
.then(function(promiseResolutions) {
render.call(res, template, _.extend({}, promiseResolutions, viewModel));
});
};
next();
};
}