WiserSolutions/quadro

parameters destructuring is failing

Closed this issue · 2 comments

module.exports = function Handler(productsRepo) {
  this.handle = async function({ message } = ctx) {
    ctx.success()   // <-- Fails here
  }
}

Error:

 ReferenceError: ctx is not defined
     ReferenceError: ctx is not defined
     at Handler.handle 

@igorshapiro This is expected behavior

The function definition above destructures ctx into a message variable instead of assigning ctx itself. The = ctx part is just a default parameter assignment but ctx itself is still not defined anywhere.

I think what you are attempting to accomplish here can somewhat be achieved using:

this.handle = async function({ message, ...ctx }) {

This will destructure message and put the rest of the fields into a ctx variable (the ctx variable will not contain message though)

Thanks @tomeresk . Closing this