Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
Abstraer los mismos parámetros de método que se llaman cada vez

Tengo un método que ayuda a responder a las solicitudes. Su firma es la siguiente:

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

Está siendo llamado docenas de veces con diferentes parámetros. Me gustaría tener un código más limpio donde llamaría

render(data, kind, route) sabiendo que req y res siempre están ahí en el contexto cuando se llama.

Como el seguiente

 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 answers
Answer question

0

Siguiendo el consejo de @deceze. Terminé usando un middleware que adjunta un cierre como el siguiente

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!