change signature of `_x` #1

layerssss opened this Issue Jan 3, 2013 · 3 comments


None yet
2 participants

Hi, I'm using IcedCoffeeScript to deal with async flow, and I found laeh is nearly pefect to work with it. eg. I can do it like

# port from
app.param 'userId', (req, res, next, userId)->
  await user.findById userId, _x defer(err,user),true,next
  req.user = user

but for CoffeeScript convention, callback shuold be placed at last, so we can write

# if we change the signature of `_x` , we can omit parentheses
app.param 'userId', (req, res, next, userId)->
  await user.findById userId, _x true, next, defer err,user
  req.user = user

.. which is cleaner. And if people just use CoffeeScript instead of IcedCoffeeScript, they can still write

# this cannot be done without changing the signature of `_x`
app.param 'userId', (req, res, next, userId)->
  await user.findById userId, _x true, next,(err,user)->
    req.user = user

So I think it will be better to have an option to change the signature of _x.


youurayy commented Jan 3, 2013

Hi, I'm not very fond of [Iced]CoffeeScript syntax — are you suggesting to swap the first two parameters of _x?

That should be doable without breaking the existing code, at a slight performance penalty of checking the type of the first parameter to be either a boolean or a function.

Alternatively, I can provide a separate function instead of _x, e.g. _z, which would be catering specifically for [Iced]CofeeScript users.

great, thanks!


youurayy commented Mar 30, 2013

hey, just getting to this. If it's still actual, please confirm the signature of _z:

// current LAEH:
_x(cb, true, funct() { })

// addition for [Iced]CoffeScript:
_z(true, cb, funct() { })

to be totally honest, I don't see how swapping the first two args helps with iced/coffeescript? The callback function you define is always at the last position, this is so that your code is cleaner...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment