cujojs / when

A solid, fast Promises/A+ and when() implementation, plus other async goodies.
Other
3.44k stars 396 forks source link

Is when.join(a, b, c, ...).spread(f) an anti-pattern? #322

Closed briancavalier closed 9 years ago

briancavalier commented 10 years ago

The exact same outcome can be achieved with:

// when.try does the same thing
var result = when.try(f, a, b, c, ...);

// or, if you want to be able to reuse or pass around a lifted f:
var fp = when.lift(f);
var result = fp(a, b, c, ...);

I think both when.join and promise.spread still have use cases separate from each other, but I'm having trouble seeing why using them together (when.join(a, b, c, ...).spread(f)) would have any advantages.

Anyone have any thoughts?

If it's true, then I'm not sure what to do, except to try harder to steer people toward when.try/lift in examples.

briancavalier commented 10 years ago

So far, my personal take is that join(a,b,c).spread(f) obscures intent. If your real goal is to call f(a, b, c), then I think when.try(f, a, b, c) communicates that goal more clearly.

The action item here seems like it should be to write the section in the anitpatterns wiki.

Additionally, maybe the only other thing we can do is to try to use when.try() instead of join().spread() in examples where possible.

brandoncarl commented 9 years ago

Brian, I found this comment to be very helpful in tidying up my own code. The when.try pattern was indeed a much better fit.

briancavalier commented 9 years ago

@brandoncarl Oh, nice, thanks for letting me know. Glad it helped!

briancavalier commented 9 years ago

Added to the wiki here. Closing.