@Jake: Do you have any examples of this use-case? When would you reuse a
promise? Currently in jsOAuth I handle success and failures with an API like
oauth.get(url, successCallback, failureCallback);
if this was a promise what would it look like? This perhaps?
var request = oauth.get(url);
request.success(successCallback);
request.failure(failureCallback);
At which point the code looks more complicated. In other examples I've seen
they do something more like
var request = oauth.get(url);
request.then(successCallback);
request.cond("failure").then(failureCallback);
Which looks even more complicated. Maybe an AJAX request is too small of a
piece of work to be using promises for?
--
Rob Griffiths
Twitter: @bytespider
Github: https://github.com/bytespider
bytespider.euSent with Sparrow (http://www.sparrowmailapp.com/?sig)
On Friday, 28 October 2011 at 12:08, Jake Verbaten wrote:
> Correct, function nesting is a flaw in architecture.
>
> however promises have their uses because you can pass them back.
>
> The main use-case for promises for me is that they say "some thing will
> happen at some point" and you can listen on that thing multiple times. A
> callback is a single callback, it will be invoked once and only once.
>
> Promises also give you a mechanism of handling errors & success seperately
> where as you have to manually do that in callbacks. I think it's just a
> pattern / style choice thing. Personally I dont use promises
>
> On Fri, Oct 28, 2011 at 11:46 AM, Rob Griffiths <[email protected]
> (mailto:[email protected])> wrote:
> > @Nick: Thanks for the link, I'll read up and may come back with more
> > thoughts and questions.
> >
> > Is function nesting that much of a problem if you design your architecture
> > properly? Surely large nests of functions and anonymous functions is just
> > sloppy coding isn't it?
> >
> > --
> > Rob Griffiths
> > Twitter: @bytespider
> > Github: https://github.com/bytespider
> >
> > bytespider.eu (http://bytespider.eu)Sent with Sparrow
> > (http://www.sparrowmailapp.com/?sig)
> >
> > On Friday, 28 October 2011 at 10:51, Nick Morgan wrote:
> >
> > > There's a large section in Test-Driven JavaScript Development
> > > (http://tddjs.com/) about converting a Node app using callbacks to one
> > > using promises. I think a big part of it is just reducing function
> > > nesting.
> > >
> > > On 27 October 2011 22:10, bytespider <[email protected]
> > > (mailto:[email protected])> wrote:
> > > > I've been thibking about promises in javascript, and whilst I think I
> > > > understand the basics i fail to see how they are useful over the usual
> > > > callback mechanisim.
> > > >
> > > > I wrote a post http://cl.ly/BMAE to summerise my thoughts and I'd
> > > > really like to start a discussion here to talk about the pros and cons
> > > > of such methodoligy.
> > > >
> > > > --
> > > > To view archived discussions from the original JSMentors Mailman list:
> > > > http://www.mail-archive.com/[email protected]/
> > > >
> > > > To search via a non-Google archive, visit here:
> > > > http://www.mail-archive.com/[email protected]/
> > > >
> > > > To unsubscribe from this group, send email to
> > > > [email protected]
> > > > (mailto:jsmentors%[email protected])
> > >
> > >
> > >
> > > --
> > > Nick Morgan
> > > http://skilldrick.co.uk
> > > @skilldrick
> > >
> > > Save our in-boxes! http://emailcharter.org
> > > --
> > > To view archived discussions from the original JSMentors Mailman list:
> > > http://www.mail-archive.com/[email protected]/
> > >
> > > To search via a non-Google archive, visit here:
> > > http://www.mail-archive.com/[email protected]/
> > >
> > > To unsubscribe from this group, send email to
> > > [email protected]
> > > (mailto:[email protected])
> >
> > --
> > To view archived discussions from the original JSMentors Mailman list:
> > http://www.mail-archive.com/[email protected]/
> >
> > To search via a non-Google archive, visit here:
> > http://www.mail-archive.com/[email protected]/
> >
> > To unsubscribe from this group, send email to
> > [email protected]
> > (mailto:jsmentors%[email protected])
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
> (mailto:[email protected])
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]