@folklore/ads
Advanced tools
Comparing version 0.0.40 to 0.0.41
@@ -887,9 +887,10 @@ 'use strict'; | ||
// Create slot | ||
const currentSlot = React.useRef(null); | ||
const slot = React.useMemo(() => { | ||
if (currentSlot.current !== null) { | ||
adsManager.destroySlot(currentSlot.current); | ||
currentSlot.current = null; | ||
} | ||
currentSlot.current = path !== null && !disabled ? adsManager.createSlot(path, size, { | ||
// const currentSlot = useRef(null); | ||
const [slot, setSlot] = React.useState(); | ||
React.useEffect(() => { | ||
// if (currentSlot.current !== null) { | ||
// adsManager.destroySlot(currentSlot.current); | ||
// currentSlot.current = null; | ||
// } | ||
const newSlot = path !== null && !disabled ? adsManager.createSlot(path, size, { | ||
visible: isVisible, | ||
@@ -900,12 +901,18 @@ sizeMapping, | ||
}) : null; | ||
setSlot(newSlot); | ||
// if (currentSlot.current !== null && adsReady) { | ||
// adsManager.defineSlot(currentSlot.current); | ||
// } | ||
return currentSlot.current; | ||
// return currentSlot.current; | ||
return () => { | ||
if (newSlot !== null) { | ||
adsManager.destroySlot(newSlot); | ||
} | ||
}; | ||
}, [adsManager, path, disabled, size, sizeMapping, alwaysRender, categoryExclusions]); | ||
React.useEffect(() => { | ||
if (currentSlot.current !== null) { | ||
currentSlot.current.setTargeting(targeting); | ||
if (slot !== null) { | ||
slot.setTargeting(targeting); | ||
} | ||
}, [targeting]); | ||
}, [slot, targeting]); | ||
@@ -978,8 +985,12 @@ // Set visibility | ||
// Destroy slot | ||
React.useEffect(() => () => { | ||
if (slot !== null) { | ||
currentSlot.current = null; | ||
adsManager.destroySlot(slot); | ||
} | ||
}, []); | ||
// useEffect( | ||
// () => () => { | ||
// if (slot !== null) { | ||
// // currentSlot.current = null; | ||
// adsManager.destroySlot(slot); | ||
// } | ||
// }, | ||
// [], | ||
// ); | ||
return { | ||
@@ -986,0 +997,0 @@ refObserver, |
@@ -869,9 +869,10 @@ import PropTypes from 'prop-types'; | ||
// Create slot | ||
const currentSlot = useRef(null); | ||
const slot = useMemo(() => { | ||
if (currentSlot.current !== null) { | ||
adsManager.destroySlot(currentSlot.current); | ||
currentSlot.current = null; | ||
} | ||
currentSlot.current = path !== null && !disabled ? adsManager.createSlot(path, size, { | ||
// const currentSlot = useRef(null); | ||
const [slot, setSlot] = useState(); | ||
useEffect(() => { | ||
// if (currentSlot.current !== null) { | ||
// adsManager.destroySlot(currentSlot.current); | ||
// currentSlot.current = null; | ||
// } | ||
const newSlot = path !== null && !disabled ? adsManager.createSlot(path, size, { | ||
visible: isVisible, | ||
@@ -882,12 +883,18 @@ sizeMapping, | ||
}) : null; | ||
setSlot(newSlot); | ||
// if (currentSlot.current !== null && adsReady) { | ||
// adsManager.defineSlot(currentSlot.current); | ||
// } | ||
return currentSlot.current; | ||
// return currentSlot.current; | ||
return () => { | ||
if (newSlot !== null) { | ||
adsManager.destroySlot(newSlot); | ||
} | ||
}; | ||
}, [adsManager, path, disabled, size, sizeMapping, alwaysRender, categoryExclusions]); | ||
useEffect(() => { | ||
if (currentSlot.current !== null) { | ||
currentSlot.current.setTargeting(targeting); | ||
if (slot !== null) { | ||
slot.setTargeting(targeting); | ||
} | ||
}, [targeting]); | ||
}, [slot, targeting]); | ||
@@ -960,8 +967,12 @@ // Set visibility | ||
// Destroy slot | ||
useEffect(() => () => { | ||
if (slot !== null) { | ||
currentSlot.current = null; | ||
adsManager.destroySlot(slot); | ||
} | ||
}, []); | ||
// useEffect( | ||
// () => () => { | ||
// if (slot !== null) { | ||
// // currentSlot.current = null; | ||
// adsManager.destroySlot(slot); | ||
// } | ||
// }, | ||
// [], | ||
// ); | ||
return { | ||
@@ -968,0 +979,0 @@ refObserver, |
{ | ||
"name": "@folklore/ads", | ||
"version": "0.0.40", | ||
"version": "0.0.41", | ||
"description": "Ads library", | ||
@@ -53,3 +53,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "9b792452940372423d526d0fb10d3f427b7ebe1c", | ||
"gitHead": "ee7a99e9a056e466320a99c43f1982d1d5900079", | ||
"dependencies": { | ||
@@ -56,0 +56,0 @@ "@folklore/hooks": "^0.0.44", |
74312
2369