Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
Abstract the same method parameters which are called everytime

I have one method that helps responding to requests. Its signature is as follows:

function render(req, res, data, kind, route)

It is being called dozens of times with different parameters. I would like to have a cleaner code where I would call

render(data, kind, route) knowing that req and res are always there in the context when calling.

As the following

router.get('/', async function (req, res, next) {
   // some logic
   // render({}, 'kind', 'route') instead of
   render(req, res, {}, 'kind', 'route')
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Following @deceze advice. I ended up using a middleware that is attaching a closure as the following

const makeRenderer = (req, res, next) => {
  res.locals.renderer = (data, kind, route) => renderer(req, res, data, kind, route)
  next()
}


router.get('/', makeRenderer, async function (req, res, next) {
  const listings = await mongoQueries.getDocumentsSince(
    20, '', req.body.pagination)
  const { page, perPage } = req.body.pagination
  const data = {
    listings: listings.documents,
    addressPoints: [],
    current: page,
    pages: Math.ceil(listings.count / perPage)
  }
  res.locals.renderer(data, 'listings', 'listings')
})
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda