@folklore/ads 0.0.40 → 0.0.41

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.
Files changed (3) hide show
  1. package/dist/cjs.js +28 -17
  2. package/dist/es.js +28 -17
  3. package/package.json +2 -2
package/dist/cjs.js CHANGED
@@ -884,28 +884,35 @@ function useAd(path, size) {
884
884
  const [renderEvent, setRenderEvent] = React.useState(null);
885
885
 
886
886
  // Create slot
887
- const currentSlot = React.useRef(null);
888
- const slot = React.useMemo(() => {
889
- if (currentSlot.current !== null) {
890
- adsManager.destroySlot(currentSlot.current);
891
- currentSlot.current = null;
892
- }
893
- currentSlot.current = path !== null && !disabled ? adsManager.createSlot(path, size, {
887
+ // const currentSlot = useRef(null);
888
+ const [slot, setSlot] = React.useState();
889
+ React.useEffect(() => {
890
+ // if (currentSlot.current !== null) {
891
+ // adsManager.destroySlot(currentSlot.current);
892
+ // currentSlot.current = null;
893
+ // }
894
+ const newSlot = path !== null && !disabled ? adsManager.createSlot(path, size, {
894
895
  visible: isVisible,
895
896
  sizeMapping,
896
897
  targeting,
897
898
  categoryExclusions
898
899
  }) : null;
900
+ setSlot(newSlot);
899
901
  // if (currentSlot.current !== null && adsReady) {
900
902
  // adsManager.defineSlot(currentSlot.current);
901
903
  // }
902
- return currentSlot.current;
904
+ // return currentSlot.current;
905
+ return () => {
906
+ if (newSlot !== null) {
907
+ adsManager.destroySlot(newSlot);
908
+ }
909
+ };
903
910
  }, [adsManager, path, disabled, size, sizeMapping, alwaysRender, categoryExclusions]);
904
911
  React.useEffect(() => {
905
- if (currentSlot.current !== null) {
906
- currentSlot.current.setTargeting(targeting);
912
+ if (slot !== null) {
913
+ slot.setTargeting(targeting);
907
914
  }
908
- }, [targeting]);
915
+ }, [slot, targeting]);
909
916
 
910
917
  // Set visibility
911
918
  React.useEffect(() => {
@@ -973,12 +980,16 @@ function useAd(path, size) {
973
980
  }, [slot, disabled, setRenderEvent, onRender, track]);
974
981
 
975
982
  // Destroy slot
976
- React.useEffect(() => () => {
977
- if (slot !== null) {
978
- currentSlot.current = null;
979
- adsManager.destroySlot(slot);
980
- }
981
- }, []);
983
+ // useEffect(
984
+ // () => () => {
985
+ // if (slot !== null) {
986
+ // // currentSlot.current = null;
987
+ // adsManager.destroySlot(slot);
988
+ // }
989
+ // },
990
+ // [],
991
+ // );
992
+
982
993
  return {
983
994
  refObserver,
984
995
  slot,
package/dist/es.js CHANGED
@@ -866,28 +866,35 @@ function useAd(path, size) {
866
866
  const [renderEvent, setRenderEvent] = useState(null);
867
867
 
868
868
  // Create slot
869
- const currentSlot = useRef(null);
870
- const slot = useMemo(() => {
871
- if (currentSlot.current !== null) {
872
- adsManager.destroySlot(currentSlot.current);
873
- currentSlot.current = null;
874
- }
875
- currentSlot.current = path !== null && !disabled ? adsManager.createSlot(path, size, {
869
+ // const currentSlot = useRef(null);
870
+ const [slot, setSlot] = useState();
871
+ useEffect(() => {
872
+ // if (currentSlot.current !== null) {
873
+ // adsManager.destroySlot(currentSlot.current);
874
+ // currentSlot.current = null;
875
+ // }
876
+ const newSlot = path !== null && !disabled ? adsManager.createSlot(path, size, {
876
877
  visible: isVisible,
877
878
  sizeMapping,
878
879
  targeting,
879
880
  categoryExclusions
880
881
  }) : null;
882
+ setSlot(newSlot);
881
883
  // if (currentSlot.current !== null && adsReady) {
882
884
  // adsManager.defineSlot(currentSlot.current);
883
885
  // }
884
- return currentSlot.current;
886
+ // return currentSlot.current;
887
+ return () => {
888
+ if (newSlot !== null) {
889
+ adsManager.destroySlot(newSlot);
890
+ }
891
+ };
885
892
  }, [adsManager, path, disabled, size, sizeMapping, alwaysRender, categoryExclusions]);
886
893
  useEffect(() => {
887
- if (currentSlot.current !== null) {
888
- currentSlot.current.setTargeting(targeting);
894
+ if (slot !== null) {
895
+ slot.setTargeting(targeting);
889
896
  }
890
- }, [targeting]);
897
+ }, [slot, targeting]);
891
898
 
892
899
  // Set visibility
893
900
  useEffect(() => {
@@ -955,12 +962,16 @@ function useAd(path, size) {
955
962
  }, [slot, disabled, setRenderEvent, onRender, track]);
956
963
 
957
964
  // Destroy slot
958
- useEffect(() => () => {
959
- if (slot !== null) {
960
- currentSlot.current = null;
961
- adsManager.destroySlot(slot);
962
- }
963
- }, []);
965
+ // useEffect(
966
+ // () => () => {
967
+ // if (slot !== null) {
968
+ // // currentSlot.current = null;
969
+ // adsManager.destroySlot(slot);
970
+ // }
971
+ // },
972
+ // [],
973
+ // );
974
+
964
975
  return {
965
976
  refObserver,
966
977
  slot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/ads",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
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": "9b792452940372423d526d0fb10d3f427b7ebe1c",
53
+ "gitHead": "ee7a99e9a056e466320a99c43f1982d1d5900079",
54
54
  "dependencies": {
55
55
  "@folklore/hooks": "^0.0.44",
56
56
  "@folklore/tracking": "^0.0.23",