parse-community / ParseReact

Seamlessly bring Parse data into your React applications.
https://parseplatform.org
Other
1.3k stars 209 forks source link

ParseReact breaks promises returned by Parse.FacebookUtils.logIn/Parse.User._logInWith/_linkWith, etc. #160

Open lrettig opened 8 years ago

lrettig commented 8 years ago

Hello,

Without ParseReact, I can call Parse.FacebookUtils.logIn using only a promise, not a callback, like so:

Parse.FacebookUtils.logIn(authData).then(function (user) {
  // do something with user
});

With ParseReact, user is always null, i.e., this promise doesn't resolve to anything. All of the functions called as part of the FacebookUtils.logIn method (Parse.User._logInWith, Parse.User._linkWith, etc.) do the right thing here and bubble up the user object via promises: at the bottom level, this is handled inside Parse.Promise._thenRunCallbacks, which ensures that the same results value is applied to a promise resolution as is sent to a success callback.

This whole flow is broken inside ParsePatches.js here:

  _linkWith: function _linkWith(provider, options) {
    return oldLinkWith.call(this, provider, options).then(function () {
      LocalSubscriptions.currentUser.update();
    });
  },

since this function accepts no argument and returns nothing, breaking the promise chain. Suggested fix:

  _linkWith: function _linkWith(provider, options) {
    return oldLinkWith.call(this, provider, options).then(function (results) {
      LocalSubscriptions.currentUser.update();
      return results;
    });
  },

Yes, it's still possible to do this using callbacks, but I prefer to use promises.

(The other, similar methods in ParsePatches.js should probably be updated too.)

Thanks.