angular-facebook
angular-facebook copied to clipboard
Deferred initialization of the provider
Hi!
Is there any way how one can init Facebook dynamically when on specific stage AppId gets known? It is being received by some query and is not defined on config phase.
So what I would like to know - is how could I provide following sequence:
- Angular initializes
- User clicks some button
- We receive appId which should be used (specific customer's)
- User gets logged in via customer's app.
Thank you in advance!
This is actually fairly big problem on our end, because we have different config settings between staging/dev and production, and we are unable to set different AppId's because of this difference.
Maybe making the Facebook.init in the run instead of a config? Alternately we can do what is mentioned here (http://stackoverflow.com/a/17500683/1519631), however this forces the user to use $http (where as using a .run means the user can provide any service they want, you can probably accept/detect if the parameter is a promise, which would mean they can initialize facebook however they want)
Might do a pull request to implement this later tonight
@Matthew, do you not have the option to define your javascript differently in different environments? Using most standard build tools you can define different values for constants in different environments.
On Sat, Sep 13, 2014 at 11:44 PM, Matthew de Detrich < [email protected]> wrote:
This is actually fairly big problem on our end, because we have different config settings between staging/dev and production, and we are unable to set different AppId's because of this difference.
Maybe making the 'Facebook.init' in the run instead of a config? Alternately we can do what is mentioned here ( http://stackoverflow.com/a/17500683/1519631), however this forces the user to use $http (where as using a .run means the user can provide any service they want, you can probably accept/detect if the parameter is a promise, which would mean they can initialize facebook however they want)
Might do a pull request to implement this later tonight
— Reply to this email directly or view it on GitHub https://github.com/Ciul/angular-facebook/issues/36#issuecomment-55517238 .
@gafilson We do have that option, however it would significantly complicate our development/production/staging cycle, seeing as our assets are statically hosted (including our javascript) in a single location
For other libraries (such as angulartics using google analytics) we are easily able to set up the id which we get when we do a request from the server. In any case its something that should definitely be possible, and I am currently coding a solution that lets you pass as a promise so you can initialize facebook ID any way you wish
Also, according to the anuglarjs irc channel, you should not be using .config for setting up stuff like id's. Its meant to be for statically defined properties, not for ID's on libraries which change depending on deployment environment
@Matthew, that makes sense to me. The current solution is inflexible.
W/r to your solution would the promise be accepted by the provider and then consumed by the service during the init of the run phase? That sounds ideal.
On Tue, Sep 23, 2014 at 11:54 PM, Matthew de Detrich < [email protected]> wrote:
@gafilson https://github.com/gafilson We do have that option, however it would significantly complicate our development/production/staging cycle, seeing as our assets are statically hosted (including our javascript) in a single location
For other libraries (such as angulartics using google analytics) we are easily able to set up the id which we get when we do a request from the server. In any case its something that should definitely be possible, and I am currently coding a solution that lets you pass as a promise so you can initialize facebook ID any way you wish
Also, according to the anuglarjs irc channel, you should not be using .config for setting up stuff like id's
— Reply to this email directly or view it on GitHub https://github.com/Ciul/angular-facebook/issues/36#issuecomment-56631575 .
My solution would retain the current option of setting an appId via .config, but you can also specify the appId in the .run phase. The implementation of the function which accepts the appId in .run phase wraps the incoming paramter as a promise using $q.when. This means if you pass in a value, it will return a promise that immediately resolves the value, and if you pass in a promise, it will return the same promise unchanged
This means if you get your appId via $http, you can just pass in the promise encapsulating the $http request and it will work fine.
Just wanna letting u know that a pitch PR would be really appreciated.
Quite busy this week, so still working on it. I have had to rewrite almost all of the test cases, while learning how karma works, should be done during this week
Just let me know if you need help about the karma tests. May you can provide the prototype first and we work out the tests together ?
I'm excited about this change. Let me know also if I can help with code reviews or anything like that.
On Mon, Sep 29, 2014 at 10:51 PM, Moritz [email protected] wrote:
Just let me know if you need help about the karma tests. May you can provide the prototype first and we work out the tests together ?
— Reply to this email directly or view it on GitHub https://github.com/Ciul/angular-facebook/issues/36#issuecomment-57270028 .
Hey guys, unfortunately I have had less time this week then originally anticipated, so I have posted what my curent implementation is. Its unfinished but the foundations are there, will have more time to look at it next week but if someone wants to help out, then that is more then welcome!
Hey guys, i'm encountering a similar problem and am very interested in the proposed fix. Can I help at all with getting this merged in?
@absolutehype there is a pull request that I have done, however its not finished yet (due to time constraints).
I suppose you can have a look at trying to finish it off, the premise is simple, config is passed through using a promise, which can mean anything (including a $http or $resource request)
Pull request is here https://github.com/Ciul/angular-facebook/issues/36
Just letting you guys know, that I am using the pull request and its working for me, just need to update and fix the tests
As an example, this is how I initialize my Facebook SDK
var facebookDefer;
facebookDefer = $q.defer();
facebookSettings.load(function(settings) {
return facebookDefer.resolve(settings.appId);
});
Facebook.initAppId(facebookDefer.promise);
facebookSettings.load just loads my appId from the server (we use require.js to manage our loading). We just wrap the loading in a standard promise, and feed the promise to Facebook.initAppId. This is in the .run, instead of .config, so you can inject things like $http and $resource without any issues
You can obviously get promises from $http or $resource. You can also put in standard values and it will work fine.
What happened with this issue? I would really love for this to be possible :)
I am using my branch in production, and its working fine. Some tests still need to be adjusted for it to work, and I haven't had time to do that (mainly because its non trivial, my branch made angular-facebook be entirely async)
If someone wants to work on my branch, they are more then welcome to do so. Else I will have some time in a couple of weeks to try and finish it off
+1
@mdedetrich just cant make it working in production with minified js, really need a solution to load it in run phase (or controllers), thoughts?
Will have a look into it in a couple of days
+1
@stewones I just had a look at the code, there is nothing indicating why it wouldn't work minified (and we use it minified in production). Can you provide any more info?
I've been using it for half a year now without any problems :)