This repository has been archived by the owner. It is now read-only.
load client configuration async #277
Closed
Conversation
| client.completePasswordReset(password, this.uid, this.code) | ||
| .done(_.bind(this._onResetCompleteSuccess, this), | ||
| _.bind(this._onResetCompleteFailure, this)); | ||
| FxaClient.getAsync() |
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 });
});
},
@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) { |
shane-tomlinson
Jan 17, 2014
Member
The context for this callback needs to be bound to this.
The context for this callback needs to be bound to this.
| this.$('h2.failure').show(); | ||
| }.bind(this)); | ||
| FxaClient.getAsync() | ||
| .then(function (client) { |
shane-tomlinson
Jan 17, 2014
Member
The context for this callback needs to be bound to this.
The context for this callback needs to be bound to this.
| console.error('Error?', err); | ||
| }.bind(this)); | ||
| FxaClient.getAsync() | ||
| .then(function (client) { |
shane-tomlinson
Jan 17, 2014
Member
Here too or else the this in the errback will be not what we expect.
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) { |
shane-tomlinson
Jan 17, 2014
Member
this here too.
this here too.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
This fixes the current build problems on stage/production. cc/ @gene1wood