From 0b62f4450cd16f581c7a0b58446fb6289a2ac1e3 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Thu, 18 Jan 2018 15:16:43 -0800 Subject: [PATCH] refactor(jade-helpers): Clean up code --- server/middlewares/jade-helpers.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/server/middlewares/jade-helpers.js b/server/middlewares/jade-helpers.js index dc45e7fb21..e8f1eca3d1 100644 --- a/server/middlewares/jade-helpers.js +++ b/server/middlewares/jade-helpers.js @@ -35,18 +35,25 @@ const cacheBreaker = isDev ? export default function jadeHelpers() { return function jadeHelpersMiddleware(req, res, next) { - res.locals.removeOldTerms = removeOldTerms; - res.locals.rev = rev; - // static data - res.locals.user = req.user; - res.locals.chunkManifest = chunkManifest; - res.locals._csrf = req.csrfToken ? req.csrfToken() : null; + Object.assign( + res.locals, + { + removeOldTerms, + rev, + cacheBreaker, + // static data + user: req.user, + chunkManifest, + _csrf: req.csrfToken ? req.csrfToken() : null, + theme: req.user && + req.user.theme || + req.cookies.theme || + 'default' + } + ); if (req.csrfToken) { res.expose({ token: res.locals._csrf }, 'csrf'); } - res.locals.theme = req.user && req.user.theme || - req.cookies.theme || - 'default'; next(); }; }