Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a race condition when refresh is called closely to defineSlots #206

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,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 @@ -373,17 +373,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 @@ -394,17 +402,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 @@ -421,7 +429,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 @@ -444,7 +452,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 @@ -483,7 +491,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