Skip to content

Commit

Permalink
Fix a race condition when refresh is called closely to defineSlots (#206
Browse files Browse the repository at this point in the history
)
  • Loading branch information
patrick-mcdougle authored Sep 24, 2020
1 parent 52e6030 commit 7de86b7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
12 changes: 7 additions & 5 deletions js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,13 @@ const DFPManager = Object.assign(new EventEmitter().setMaxListeners(0), {
if (loadPromise === null) {
this.load();
} else {
this.gptRefreshAds(
Object.keys(
this.getRefreshableSlots(...slots),
),
);
loadPromise.then(() => {
this.gptRefreshAds(
Object.keys(
this.getRefreshableSlots(...slots),
),
);
});
}
},

Expand Down
30 changes: 19 additions & 11 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,25 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
}, slots);
},
refresh: function refresh() {
var _this6 = this;

for (var _len4 = arguments.length, slots = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
slots[_key4] = arguments[_key4];
}

if (loadPromise === null) {
this.load();
} else {
this.gptRefreshAds(Object.keys(this.getRefreshableSlots.apply(this, arguments)));
loadPromise.then(function () {
_this6.gptRefreshAds(Object.keys(_this6.getRefreshableSlots.apply(_this6, slots)));
});
}
},
gptRefreshAds: function gptRefreshAds(slots) {
var _this6 = this;
var _this7 = this;

return this.getGoogletag().then(function (googletag) {
_this6.configureOptions(googletag);
_this7.configureOptions(googletag);

googletag.cmd.push(function () {
var pubadsService = googletag.pubads();
Expand All @@ -390,17 +398,17 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
});
},
reload: function reload() {
var _this7 = this;
var _this8 = this;

return this.destroyGPTSlots.apply(this, arguments).then(function () {
return _this7.load();
return _this8.load();
});
},
destroyGPTSlots: function destroyGPTSlots() {
var _this8 = this;
var _this9 = this;

for (var _len4 = arguments.length, slotsToDestroy = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
slotsToDestroy[_key4] = arguments[_key4];
for (var _len5 = arguments.length, slotsToDestroy = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
slotsToDestroy[_key5] = arguments[_key5];
}

if (slotsToDestroy.length === 0) {
Expand All @@ -417,7 +425,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
slots.push(slot);
}

_this8.getGoogletag().then(function (googletag) {
_this9.getGoogletag().then(function (googletag) {
googletag.cmd.push(function () {
if (managerAlreadyInitialized === true) {
if (slotsToDestroy.length > 0) {
Expand All @@ -440,7 +448,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
});
},
registerSlot: function registerSlot(_ref) {
var _this9 = this;
var _this10 = this;

var slotId = _ref.slotId,
dfpNetworkId = _ref.dfpNetworkId,
Expand Down Expand Up @@ -479,7 +487,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), {
gptSlot = slot.gptSlot;

if (loading === false && !gptSlot) {
_this9.load(slotId);
_this10.load(slotId);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-dfp",
"version": "0.18.0",
"version": "0.19.0",
"homepage": "https://github.com/jaanauati/react-dfp/",
"author": {
"name": "Jonatan Alexis Anauati",
Expand Down

0 comments on commit 7de86b7

Please sign in to comment.