Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple .then calls will only fire the last .then callback #20

Open
banderso-n opened this issue Apr 4, 2016 · 10 comments
Open

Multiple .then calls will only fire the last .then callback #20

banderso-n opened this issue Apr 4, 2016 · 10 comments

Comments

@banderso-n
Copy link

I have two modules that call .then on the promise returned from an ajax().post call.

// module 1
proto.method = function () {
  return ajax().post(...).then(function (response) {
    // This will not fire if there's a `then` call in module2.method
  });
};

// module 2
proto.method = function () {
  module1.method().then(function (response) {
    // This will fire because it was the last .then to be invoked
  });
};

Only the last callback "registered" with a then call will be invoked. As this is promise-based, I expect to be able to chain then/catch/always calls.

@fdaciuk
Copy link
Owner

fdaciuk commented Apr 4, 2016

Hi @banderso-n! This is the expected behaviour (for now).
The chainable .then implementation to work as Promises doesn't was implemented yet.

Feel free to send a pull request =)

@statianzo
Copy link

@fdaciuk what are your thoughts on just using native promises?
http://caniuse.com/#feat=promises

@fdaciuk
Copy link
Owner

fdaciuk commented Aug 5, 2016

I think so =)

But I think it will be better if something like babel promise plugin is used instead.

What do you think about it?

@statianzo
Copy link

I vote for the simple route of assuming the native Promise global exists. It's available on every modern platform and most polyfills support creating a global if necessary.

Using the babel plugin would force users into es6-promise even if they wanted to use bluebird or some other promise library.

@fdaciuk
Copy link
Owner

fdaciuk commented Aug 5, 2016

Make sense, but that's not enough =)
And if user haven't any other promise library included on project? Ajax must work even in this case.
The main idea from this library is that it abstracts XMLHttpRequest, using Promises - or something like xD

I thought in create a mini library, based on Promise/A+ spec to solve this.

@statianzo
Copy link

If they don't have a promise polyfill included and they have to support legacy environments without native Promises built in then they should use a polyfill. There shouldn't be a need to create another promise library, there are already quite a few popular choices:

https://github.com/stefanpenner/es6-promise
https://github.com/petkaantonov/bluebird
https://github.com/tildeio/rsvp.js
https://github.com/then/promise
https://github.com/stackp/promisejs
...and the list goes on

If ajax were to pick a promise library (or create its own), then users of a different promise library would need to have 2 promise libraries loaded. By assuming a Promise global (or possibly passing in an option to ajax()), it gives more control to users.

@statianzo
Copy link

Opened #38 as a discussion point.

@kenberkeley
Copy link

the non-standard promise almost ruined my project...

@fabiocbinbutter
Copy link

@kenberkeley what did you end up doing/using instead?
I chased a bug caused by this for about an hour...

@kenberkeley
Copy link

@fabiocbinbutter wrap with the native promise...

Repository owner deleted a comment Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants