-
Notifications
You must be signed in to change notification settings - Fork 69
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
$q promises for async calls #1
Comments
Hello @pspeter3, thank you for asking! After looking through the code, you'll find out that the current callback function's angular context application($rootScope.$apply) is actually determined by the user. The wrapped angular.forEach(args, function (arg, i) {
/**
* Wrap API function arg with angularjs context
*/
if (angular.isFunction(arg)) {
var func = arg;
args[i] = function () {
var funcArgs = Array.prototype.slice.call(arguments);
if ($rootScope.$$phase) {
// already in angularjs context
func.apply(null, funcArgs);
}
else {
// not in angularjs context
$rootScope.$apply(function () {
func.apply(null, funcArgs);
});
}
};
}
}); So the difficulty for returning $q promise is
And I come up with a solution for that - always present the original callback function with an /**
* Modified API demo
*/
$FB.getLoginStatus(null)
.then(function (res) {
$scope.loginStatus = res;
return $FB.api('/me', null);
})
.then(function (res) {
$scope.apiMe = res;
});
/**
* Combined with $q.all
*/
$q.all([
$FB.api('/me', null),
$FB.getLoginStatus(null, true),
$FB.ui(options, null)
])
.then(function (rsvList) {
var apiMeRes = rsvList[0],
loginStatusRes = rsvList[1],
uiRes = rsvList[2];
}); Otherwise, I'll have to specify which argument in each method is the callback function in reference to Facebook JavaScript SDK doc. |
Fair enough, do you think it's worth specifying it? |
Sure. I'll try to implement the feature this weekend. |
Thanks! |
Hi @pspeter3 , I just pushed the version supports $q promise to Here's an new version of demo for $q promise version The |
That looks awesome. Thank you! |
Looking through the code, I'm trying to understand how difficult it would be to wrap the async calls to facebook with $q and tie in the events to the angular event system. Thoughts?
The text was updated successfully, but these errors were encountered: