Comments (6)
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 $FB
APIs try to extract the arguments from your input, find out any is function
argument, then $apply
the angular context to it.
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
If there's no callback function presented, wrapper function wouln't know where to $apply angular context, hence failing to resolve the $q promise
And I come up with a solution for that - always present the original callback function with an angular.noop(empty function)
or a null
value. Here's an example how it will look like after implementation:
/**
* 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.
from angular-easyfb.
Fair enough, do you think it's worth specifying it?
from angular-easyfb.
Sure. I'll try to implement the feature this weekend.
from angular-easyfb.
Thanks!
from angular-easyfb.
Hi @pspeter3 ,
I just pushed the version supports $q promise to develop
branch,
please try it and let me know whether it works well or not.
And I'll merge it to master
if it does work well, thanks!!
Here's an new version of demo for $q promise version
http://plnkr.co/edit/UMUtFc?p=preview
The develop
version of includable scripts are available at
- http://pc035860.github.io/angular-easyfb/angular-easyfb.dev.js
- http://pc035860.github.io/angular-easyfb/angular-easyfb.dev.min.js
from angular-easyfb.
That looks awesome. Thank you!
from angular-easyfb.
Related Issues (20)
- Facebook Comment And Like Track HOT 9
- Page Plugin not loading on iPad Safari iOS 9.2.1 HOT 1
- "Main" field in package.json is wrong HOT 2
- Upload photos from camera source HOT 3
- Won't initialize when `xfbml: false` given
- Unsupported Browser:: Facebook login does not work from chrome on iPhone. HOT 2
- Minified version of 1.4.4 causes injector error HOT 2
- Dynamic set the locale HOT 2
- Get ezfb to work with import HOT 2
- To show all public posts that are present in Page or a person in facebook?? HOT 3
- apk file created by android studio using ionic framework not working HOT 2
- facebook endpoint changed from *.net to *.com HOT 2
- Angular2 Version? HOT 2
- can i make the custom fb like button and call some controller function on click of that button. HOT 1
- doesn't render FB login button after navigating to different page and back HOT 3
- long-lived token
- How to use fb-login-button directive HOT 1
- In Android device error getting the sdk
- Login Button doesn't work HOT 3
- No way to exchange short-term tokens for long-term tokens
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-easyfb.