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

Deferred initialization of the provider #36

Open
k41n opened this issue Mar 10, 2014 · 21 comments
Open

Deferred initialization of the provider #36

k41n opened this issue Mar 10, 2014 · 21 comments

Comments

@k41n
Copy link

k41n commented Mar 10, 2014

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:

  1. Angular initializes
  2. User clicks some button
  3. We receive appId which should be used (specific customer's)
  4. User gets logged in via customer's app.

Thank you in advance!

@mdedetrich
Copy link

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

@gafilson
Copy link

@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 <
notifications@github.com> 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
#36 (comment)
.

@mdedetrich
Copy link

@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

@gafilson
Copy link

@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 <
notifications@github.com> 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
#36 (comment)
.

@mdedetrich
Copy link

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.

@mrzmyr
Copy link
Collaborator

mrzmyr commented Sep 25, 2014

Just wanna letting u know that a pitch PR would be really appreciated.

@mdedetrich
Copy link

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

@mrzmyr
Copy link
Collaborator

mrzmyr commented Sep 30, 2014

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 ?

@gafilson
Copy link

gafilson commented Oct 1, 2014

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 notifications@github.com 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
#36 (comment)
.

@mdedetrich
Copy link

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!

@absolutehype
Copy link

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?

@mdedetrich
Copy link

@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
#36

@mdedetrich
Copy link

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.

@TheWrongAlice
Copy link

What happened with this issue?
I would really love for this to be possible :)

@mdedetrich
Copy link

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

@stewones
Copy link

+1

@stewones
Copy link

@mdedetrich just cant make it working in production with minified js, really need a solution to load it in run phase (or controllers), thoughts?

@mdedetrich
Copy link

Will have a look into it in a couple of days

@IRRAT
Copy link

IRRAT commented Nov 18, 2015

+1

@mdedetrich
Copy link

@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?

@TheWrongAlice
Copy link

I've been using it for half a year now without any problems :)

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

9 participants