Skip to content

Commit d95ba9c

Browse files
author
Gabriel Galvao da Gama
committed
Added js docs and reduced parameters
1 parent c98919b commit d95ba9c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,13 @@ define([
358358
return deferred.promise();
359359
},
360360

361-
onAjaxComplete: function(event, xhr, settings) {
361+
/**
362+
* Reload sections on ajax complete
363+
*
364+
* @param {Object} jsonResponse
365+
* @param {Object} settings
366+
*/
367+
onAjaxComplete: function(jsonResponse, settings) {
362368
var sections,
363369
redirects;
364370

@@ -369,7 +375,7 @@ define([
369375
this.invalidate(sections);
370376
redirects = ['redirect', 'backUrl'];
371377

372-
if (_.isObject(xhr.responseJSON) && !_.isEmpty(_.pick(xhr.responseJSON, redirects))) { //eslint-disable-line
378+
if (_.isObject(jsonResponse) && !_.isEmpty(_.pick(jsonResponse, redirects))) { //eslint-disable-line
373379
return;
374380
}
375381
this.reload(sections, true);
@@ -395,7 +401,7 @@ define([
395401
* Events listener
396402
*/
397403
$(document).on('ajaxComplete', function (event, xhr, settings) {
398-
customerData.onAjaxComplete(event, xhr, settings);
404+
customerData.onAjaxComplete(xhr.responseJSON, settings);
399405
});
400406

401407
/**

dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/customer-data.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,16 @@ define([
512512

513513
describe('"onAjaxComplete" method', function () {
514514
it('Should not trigger reload if sections is empty', function () {
515-
var event, xhr, settings;
515+
var jsonResponse, settings;
516516

517-
event = jasmine.createSpy().and.returnValue($.event);
518-
xhr = jasmine.createSpy();
517+
jsonResponse = jasmine.createSpy();
519518
spyOn(sectionConfig, 'getAffectedSections').and.returnValue([]);
520519
spyOn(obj, 'reload');
521520
settings = {
522521
type: "POST",
523522
url: "http://test.local"
524523
};
525-
obj.onAjaxComplete(event, xhr, settings);
524+
obj.onAjaxComplete(jsonResponse, settings);
526525
expect(obj.reload).not.toHaveBeenCalled();
527526
});
528527
});

0 commit comments

Comments
 (0)