Skip to content
This repository has been archived by the owner. It is now read-only.

load client configuration async #277

Closed
wants to merge 1 commit into from
Closed

load client configuration async #277

wants to merge 1 commit into from

Conversation

@zaach
Copy link
Contributor

@zaach zaach commented Jan 17, 2014

This fixes the current build problems on stage/production. cc/ @gene1wood

client.completePasswordReset(password, this.uid, this.code)
.done(_.bind(this._onResetCompleteSuccess, this),
_.bind(this._onResetCompleteFailure, this));
FxaClient.getAsync()

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jan 17, 2014
Member

@zaach - since all of the client wrapper functions return a promise, we should be able to abstract the real client creation within app/lib/fxa-client.js and avoid all of the FxaClient.getAsync() business.

I am experimenting with this approach now, and thinking something along the lines of:

  function FxaClientWrapper() {
  }

  FxaClientWrapper.prototype = {
    _withClient: function () {
      var defer = $.Deferred();

      if (this.fxaClient) {
        defer.resolve(this.fxaClient);
      } else {
        $.getJSON('/config', function (data) {
          this.fxaClient = new FxaClient(data.fxaccountUrl);
          defer.resolve(this.fxaClient);
        }.bind(this));
      }

      return defer.promise();
    },

    signIn: function (email, password) {
      return this._withClient()
                .then(function (client) {
                  return client.signIn(email, password, { keys: true });
                });
    },
.done(_.bind(this._onResetCompleteSuccess, this),
_.bind(this._onResetCompleteFailure, this));
FxaClient.getAsync()
.then(function (client) {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jan 17, 2014
Member

The context for this callback needs to be bound to this.

this.$('h2.failure').show();
}.bind(this));
FxaClient.getAsync()
.then(function (client) {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jan 17, 2014
Member

The context for this callback needs to be bound to this.

console.error('Error?', err);
}.bind(this));
FxaClient.getAsync()
.then(function (client) {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jan 17, 2014
Member

Here too or else the this in the errback will be not what we expect.

.done(this._onRequestResetSuccess.bind(this),
this._onRequestResetFailure.bind(this));
FxaClient.getAsync()
.then(function (client) {

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Jan 17, 2014
Member

this here too.

@zaach zaach closed this Jan 17, 2014
@zaach zaach deleted the reconfig branch Jan 17, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants