Closed khowling closed 8 years ago
In my project where I'm using jexl, we require content like that to be passed into the transform, either as the subject or one of the arguments.
To allow for this in a non-breaking change, I could send the expression's context object as either the final argument to the transform, or set it to this
inside of the transform function.
I'm torn, as I don't particularly love either of these solutions. The argument would have inconsistent placement depending on how many arguments the user sends to the transform, and setting the this
execution context would preclude access to the local scope when using an arrow function.
Will chew on this a bit more-- in the meantime, I'm very open to implementation ideas.
Thought about this for a bit, and I'm curious: why not send the arguments your transform needs to the transform when you call it?
jexl.eval("someVar|myTransform(req.user)", {someVar, req})
.then(...)
Closing in favor of using arguments to support this use case, but if anyone can make a strong case for setting this
in the transform function to the context object, I'd love to hear it. My only reason for not doing that at the moment is to avoid potential ugly misuse of transform functions.
I need to access req.user in my transformers, what is the best way to do this? I love this project by the way, thank you!