<commit_before>/* global FB, $ */

/**
 * This class implements authentication against facebook
 * connect using the Facebook SDK.
 */

import Endpoint from 'torii/endpoints/-base';
import {configurable} from 'torii/configuration';
import Authentication from 'torii/authentications/facebook';

var fbPromise;

function fbLoad(settings){
  if (fbPromise) { return fbPromise; }

  var original = window.fbAsyncInit;
  fbPromise = new Ember.RSVP.Promise(function(resolve, reject){
    window.fbAsyncInit = function(){
      FB.init(settings);
      Ember.run(null, resolve);
    };
    $.getScript('//connect.facebook.net/en_US/all.js');
  }).then(function(){
    window.fbAsyncInit = original;
  });

  return fbPromise;
}

function fbLogin(){
  return new Ember.RSVP.Promise(function(resolve, reject){
    FB.login(function(response){
      if (response.authResponse) {
        resolve(response.authResponse);
      } else {
        reject(response.status);
      }
    });
  });
}

function fbNormalize(response){
  return Authentication.create({
    userId: response.userID,
    accessToken: response.accessToken
  });
}<commit_msg>Resolve FB.login promise in runloop<commit_after>/* global FB, $ */

/**
 * This class implements authentication against facebook
 * connect using the Facebook SDK.
 */

import Endpoint from 'torii/endpoints/-base';
import {configurable} from 'torii/configuration';
import Authentication from 'torii/authentications/facebook';

var fbPromise;

function fbLoad(settings){
  if (fbPromise) { return fbPromise; }

  var original = window.fbAsyncInit;
  fbPromise = new Ember.RSVP.Promise(function(resolve, reject){
    window.fbAsyncInit = function(){
      FB.init(settings);
      Ember.run(null, resolve);
    };
    $.getScript('//connect.facebook.net/en_US/all.js');
  }).then(function(){
    window.fbAsyncInit = original;
  });

  return fbPromise;
}

function fbLogin(){
  return new Ember.RSVP.Promise(function(resolve, reject){
    FB.login(function(response){
      if (response.authResponse) {
        Ember.run(null, resolve, response.authResponse);
      } else {
        Ember.run(null, reject, response.status);
      }
    });
  });
}

function fbNormalize(response){
  return Authentication.create({
    userId: response.userID,
    accessToken: response.accessToken
  });
}
{'fraction_non_alphanumeric': 0.1330749354005168, 'fraction_numerical': 0.0, 'mean_word_length': 3.7215447154471546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3733608', 'n_tokens_mistral': 721, 'n_tokens_neox': 689, 'n_words': 152}