@folklore/ads 0.0.61 → 0.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs.js +23 -1
- package/dist/es.js +23 -1
- package/package.json +2 -2
package/dist/cjs.js
CHANGED
|
@@ -209,6 +209,7 @@ class AdSlot extends EventEmitter__default["default"] {
|
|
|
209
209
|
this.displayed = false;
|
|
210
210
|
this.renderEvent = null;
|
|
211
211
|
this.destroyed = true;
|
|
212
|
+
this.emit('destroy', this);
|
|
212
213
|
}
|
|
213
214
|
getElementId() {
|
|
214
215
|
return this.elementId;
|
|
@@ -286,6 +287,7 @@ class AdsManager extends EventEmitter__default["default"] {
|
|
|
286
287
|
// return newId;
|
|
287
288
|
// }
|
|
288
289
|
|
|
290
|
+
static ID_PREFIX = 'div-gpt-ad-';
|
|
289
291
|
static getArticleTargeting(article) {
|
|
290
292
|
if (article === null) {
|
|
291
293
|
return null;
|
|
@@ -359,7 +361,7 @@ class AdsManager extends EventEmitter__default["default"] {
|
|
|
359
361
|
// const newId = `div-gpt-ad-${new Date().getTime()}-${Math.round(
|
|
360
362
|
// Math.random() * (Math.random() * 1000),
|
|
361
363
|
// )}-${this.index}`;
|
|
362
|
-
const newId =
|
|
364
|
+
const newId = `${AdsManager.ID_PREFIX}${this.index}`;
|
|
363
365
|
this.index += 1;
|
|
364
366
|
return newId;
|
|
365
367
|
}
|
|
@@ -576,6 +578,7 @@ class AdsManager extends EventEmitter__default["default"] {
|
|
|
576
578
|
googletag.destroySlots([adSlot]);
|
|
577
579
|
});
|
|
578
580
|
}
|
|
581
|
+
this.emit('destroy:slot', slot);
|
|
579
582
|
}
|
|
580
583
|
refreshSlot(id) {
|
|
581
584
|
const {
|
|
@@ -854,6 +857,7 @@ function useAd(path, size) {
|
|
|
854
857
|
refreshInterval = null,
|
|
855
858
|
alwaysRender = false,
|
|
856
859
|
onRender = null,
|
|
860
|
+
onDestroy = null,
|
|
857
861
|
disabled = false,
|
|
858
862
|
disableTracking = false,
|
|
859
863
|
rootMargin = '300px'
|
|
@@ -988,6 +992,20 @@ function useAd(path, size) {
|
|
|
988
992
|
return () => slot.off('render', onSlotRender);
|
|
989
993
|
}, [slot, disabled, setRenderEvent, onRender, track]);
|
|
990
994
|
|
|
995
|
+
// Listen to destroy event
|
|
996
|
+
React.useEffect(() => {
|
|
997
|
+
if (slot === null) {
|
|
998
|
+
return () => {};
|
|
999
|
+
}
|
|
1000
|
+
const onSlotDestroy = destroySlot => {
|
|
1001
|
+
if (onDestroy !== null) {
|
|
1002
|
+
onDestroy(destroySlot);
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
slot.on('destroy', onSlotDestroy);
|
|
1006
|
+
return () => slot.off('destroy', onSlotDestroy);
|
|
1007
|
+
}, [slot, onDestroy]);
|
|
1008
|
+
|
|
991
1009
|
// Destroy slot
|
|
992
1010
|
// useEffect(
|
|
993
1011
|
// () => () => {
|
|
@@ -1031,6 +1049,7 @@ const propTypes = {
|
|
|
1031
1049
|
emptyClassName: PropTypes__default["default"].string,
|
|
1032
1050
|
adClassName: PropTypes__default["default"].string,
|
|
1033
1051
|
onRender: PropTypes__default["default"].func,
|
|
1052
|
+
onDestroy: PropTypes__default["default"].func,
|
|
1034
1053
|
slotRef: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object])
|
|
1035
1054
|
};
|
|
1036
1055
|
const defaultProps = {
|
|
@@ -1049,6 +1068,7 @@ const defaultProps = {
|
|
|
1049
1068
|
emptyClassName: null,
|
|
1050
1069
|
adClassName: null,
|
|
1051
1070
|
onRender: null,
|
|
1071
|
+
onDestroy: null,
|
|
1052
1072
|
slotRef: null
|
|
1053
1073
|
};
|
|
1054
1074
|
function Ad(_ref) {
|
|
@@ -1069,6 +1089,7 @@ function Ad(_ref) {
|
|
|
1069
1089
|
emptyClassName,
|
|
1070
1090
|
adClassName,
|
|
1071
1091
|
onRender,
|
|
1092
|
+
onDestroy,
|
|
1072
1093
|
slotRef
|
|
1073
1094
|
} = _ref;
|
|
1074
1095
|
const {
|
|
@@ -1162,6 +1183,7 @@ function Ad(_ref) {
|
|
|
1162
1183
|
refreshInterval: finalAdTargeting.refreshInterval,
|
|
1163
1184
|
alwaysRender,
|
|
1164
1185
|
onRender: onAdRender,
|
|
1186
|
+
onDestroy,
|
|
1165
1187
|
disabled: finalDisabled,
|
|
1166
1188
|
disableTracking
|
|
1167
1189
|
});
|
package/dist/es.js
CHANGED
|
@@ -191,6 +191,7 @@ class AdSlot extends EventEmitter {
|
|
|
191
191
|
this.displayed = false;
|
|
192
192
|
this.renderEvent = null;
|
|
193
193
|
this.destroyed = true;
|
|
194
|
+
this.emit('destroy', this);
|
|
194
195
|
}
|
|
195
196
|
getElementId() {
|
|
196
197
|
return this.elementId;
|
|
@@ -268,6 +269,7 @@ class AdsManager extends EventEmitter {
|
|
|
268
269
|
// return newId;
|
|
269
270
|
// }
|
|
270
271
|
|
|
272
|
+
static ID_PREFIX = 'div-gpt-ad-';
|
|
271
273
|
static getArticleTargeting(article) {
|
|
272
274
|
if (article === null) {
|
|
273
275
|
return null;
|
|
@@ -341,7 +343,7 @@ class AdsManager extends EventEmitter {
|
|
|
341
343
|
// const newId = `div-gpt-ad-${new Date().getTime()}-${Math.round(
|
|
342
344
|
// Math.random() * (Math.random() * 1000),
|
|
343
345
|
// )}-${this.index}`;
|
|
344
|
-
const newId =
|
|
346
|
+
const newId = `${AdsManager.ID_PREFIX}${this.index}`;
|
|
345
347
|
this.index += 1;
|
|
346
348
|
return newId;
|
|
347
349
|
}
|
|
@@ -558,6 +560,7 @@ class AdsManager extends EventEmitter {
|
|
|
558
560
|
googletag.destroySlots([adSlot]);
|
|
559
561
|
});
|
|
560
562
|
}
|
|
563
|
+
this.emit('destroy:slot', slot);
|
|
561
564
|
}
|
|
562
565
|
refreshSlot(id) {
|
|
563
566
|
const {
|
|
@@ -836,6 +839,7 @@ function useAd(path, size) {
|
|
|
836
839
|
refreshInterval = null,
|
|
837
840
|
alwaysRender = false,
|
|
838
841
|
onRender = null,
|
|
842
|
+
onDestroy = null,
|
|
839
843
|
disabled = false,
|
|
840
844
|
disableTracking = false,
|
|
841
845
|
rootMargin = '300px'
|
|
@@ -970,6 +974,20 @@ function useAd(path, size) {
|
|
|
970
974
|
return () => slot.off('render', onSlotRender);
|
|
971
975
|
}, [slot, disabled, setRenderEvent, onRender, track]);
|
|
972
976
|
|
|
977
|
+
// Listen to destroy event
|
|
978
|
+
useEffect(() => {
|
|
979
|
+
if (slot === null) {
|
|
980
|
+
return () => {};
|
|
981
|
+
}
|
|
982
|
+
const onSlotDestroy = destroySlot => {
|
|
983
|
+
if (onDestroy !== null) {
|
|
984
|
+
onDestroy(destroySlot);
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
slot.on('destroy', onSlotDestroy);
|
|
988
|
+
return () => slot.off('destroy', onSlotDestroy);
|
|
989
|
+
}, [slot, onDestroy]);
|
|
990
|
+
|
|
973
991
|
// Destroy slot
|
|
974
992
|
// useEffect(
|
|
975
993
|
// () => () => {
|
|
@@ -1013,6 +1031,7 @@ const propTypes = {
|
|
|
1013
1031
|
emptyClassName: PropTypes.string,
|
|
1014
1032
|
adClassName: PropTypes.string,
|
|
1015
1033
|
onRender: PropTypes.func,
|
|
1034
|
+
onDestroy: PropTypes.func,
|
|
1016
1035
|
slotRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
|
1017
1036
|
};
|
|
1018
1037
|
const defaultProps = {
|
|
@@ -1031,6 +1050,7 @@ const defaultProps = {
|
|
|
1031
1050
|
emptyClassName: null,
|
|
1032
1051
|
adClassName: null,
|
|
1033
1052
|
onRender: null,
|
|
1053
|
+
onDestroy: null,
|
|
1034
1054
|
slotRef: null
|
|
1035
1055
|
};
|
|
1036
1056
|
function Ad(_ref) {
|
|
@@ -1051,6 +1071,7 @@ function Ad(_ref) {
|
|
|
1051
1071
|
emptyClassName,
|
|
1052
1072
|
adClassName,
|
|
1053
1073
|
onRender,
|
|
1074
|
+
onDestroy,
|
|
1054
1075
|
slotRef
|
|
1055
1076
|
} = _ref;
|
|
1056
1077
|
const {
|
|
@@ -1144,6 +1165,7 @@ function Ad(_ref) {
|
|
|
1144
1165
|
refreshInterval: finalAdTargeting.refreshInterval,
|
|
1145
1166
|
alwaysRender,
|
|
1146
1167
|
onRender: onAdRender,
|
|
1168
|
+
onDestroy,
|
|
1147
1169
|
disabled: finalDisabled,
|
|
1148
1170
|
disableTracking
|
|
1149
1171
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/ads",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.63",
|
|
4
4
|
"description": "Ads library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "5758c6b7d203e04862d82991e990b9f806485da3",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@folklore/hooks": "^0.0.58",
|
|
56
56
|
"@folklore/tracking": "^0.0.23",
|