@folklore/hooks 0.0.64 → 0.0.66

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 +20 -24
  2. package/dist/es.js +10 -5
  3. package/package.json +5 -5
package/dist/cjs.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var raf = require('raf');
6
4
  var react = require('react');
7
5
  var services = require('@folklore/services');
@@ -10,13 +8,6 @@ var EventsManager = require('@folklore/events');
10
8
  var cancelablePromise = require('cancelable-promise');
11
9
  var isNumber = require('lodash/isNumber');
12
10
 
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
-
15
- var raf__default = /*#__PURE__*/_interopDefaultLegacy(raf);
16
- var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
17
- var EventsManager__default = /*#__PURE__*/_interopDefaultLegacy(EventsManager);
18
- var isNumber__default = /*#__PURE__*/_interopDefaultLegacy(isNumber);
19
-
20
11
  function useCounter(desiredValue, _ref) {
21
12
  let {
22
13
  disabled = false,
@@ -48,20 +39,20 @@ function useCounter(desiredValue, _ref) {
48
39
  const newValue = Math.round(startValue + progress * delta);
49
40
  setCurrentValue(newValue);
50
41
  if (newValue !== desiredValue) {
51
- animationFrame = raf__default["default"](loop);
42
+ animationFrame = raf(loop);
52
43
  }
53
44
  }
54
45
  if (delta !== 0) {
55
46
  duration = Math.min(maxDuration, Math.abs(delta) * speed * 1000);
56
47
  startTime = Date.now();
57
- animationFrame = raf__default["default"](loop);
48
+ animationFrame = raf(loop);
58
49
  } else if (disabled) {
59
50
  setCurrentValue(desiredValue);
60
51
  }
61
52
  return () => {
62
53
  canceled = true;
63
54
  if (animationFrame !== null) {
64
- raf__default["default"].cancel(animationFrame);
55
+ raf.cancel(animationFrame);
65
56
  }
66
57
  };
67
58
  }, [desiredValue, disabled, initialValue, maxDuration, speed]);
@@ -95,7 +86,7 @@ function useDailymotionPlayer() {
95
86
  return null;
96
87
  }
97
88
  } = params;
98
- const debug = react.useMemo(() => createDebug__default["default"]('folklore:video:dailymotion'), []);
89
+ const debug = react.useMemo(() => createDebug('folklore:video:dailymotion'), []);
99
90
  const [apiLoaded, setApiLoaded] = react.useState(typeof window !== 'undefined' && typeof window.dailymotion !== 'undefined');
100
91
  const [playerReady, setPlayerReady] = react.useState(false);
101
92
  const [loaded, setLoaded] = react.useState(false);
@@ -399,7 +390,7 @@ function useDailymotionPlayer() {
399
390
  };
400
391
  }
401
392
 
402
- const eventsManager$1 = typeof document !== 'undefined' ? new EventsManager__default["default"](document) : null;
393
+ const eventsManager$1 = typeof document !== 'undefined' ? new EventsManager(document) : null;
403
394
  function useDocumentEvent(event, callback) {
404
395
  react.useEffect(() => {
405
396
  if (eventsManager$1 !== null && callback !== null) {
@@ -629,7 +620,7 @@ function useIsVisible() {
629
620
  };
630
621
  }
631
622
 
632
- const eventsManager = typeof window !== 'undefined' ? new EventsManager__default["default"](window) : null;
623
+ const eventsManager = typeof window !== 'undefined' ? new EventsManager(window) : null;
633
624
  function useWindowEvent(event, callback) {
634
625
  react.useEffect(() => {
635
626
  if (eventsManager !== null && callback !== null) {
@@ -764,7 +755,7 @@ const useItemsPaginated = function (loader) {
764
755
  }
765
756
  return aPage > bPage ? 1 : -1;
766
757
  }
767
- if (isNumber__default["default"](a) && isNumber__default["default"](b)) {
758
+ if (isNumber(a) && isNumber(b)) {
768
759
  if (a === b) {
769
760
  return 0;
770
761
  }
@@ -940,7 +931,7 @@ function useNativeVideoPlayer(url) {
940
931
  timeUpdateInterval = 1000,
941
932
  onTimeUpdate: customOnTimeUpdate = null
942
933
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
943
- const debug = react.useMemo(() => createDebug__default["default"]('folklore:video:native'), []);
934
+ const debug = react.useMemo(() => createDebug('folklore:video:native'), []);
944
935
  const elementRef = react.useRef(null);
945
936
  const [loaded, setLoaded] = react.useState(false);
946
937
  const [volume, setVolumeState] = react.useState(initialMuted ? 0 : 1);
@@ -1131,7 +1122,7 @@ function useVimeoPlayer(id) {
1131
1122
  return match !== null ? match[1] : null;
1132
1123
  }
1133
1124
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1134
- const debug = react.useMemo(() => createDebug__default["default"]('folklore:video:vimeo'), []);
1125
+ const debug = react.useMemo(() => createDebug('folklore:video:vimeo'), []);
1135
1126
  const [apiLoaded, setApiLoaded] = react.useState(false);
1136
1127
  const apiRef = react.useRef(null);
1137
1128
  const elementRef = react.useRef(null);
@@ -1433,7 +1424,7 @@ function useYouTubePlayer(id) {
1433
1424
  return match !== null ? match[7] : null;
1434
1425
  }
1435
1426
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1436
- const debug = react.useMemo(() => createDebug__default["default"]('folklore:video:youtube'), []);
1427
+ const debug = react.useMemo(() => createDebug('folklore:video:youtube'), []);
1437
1428
  const [apiLoaded, setApiLoaded] = react.useState(typeof window !== 'undefined' && typeof window.YT !== 'undefined');
1438
1429
  const apiRef = react.useRef(typeof window !== 'undefined' && typeof window.YT !== 'undefined' ? window.YT : null);
1439
1430
  const elementRef = react.useRef(null);
@@ -1742,17 +1733,19 @@ function useWindowSize() {
1742
1733
  onChange = null
1743
1734
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1744
1735
  const [size, setSize] = react.useState(currentSize);
1736
+ const sizeRef = react.useRef(size);
1745
1737
  const updateSize = react.useCallback(() => {
1746
1738
  const newSize = getWindowSize();
1747
1739
  if (currentSize.width !== newSize.width || currentSize.height !== newSize.height) {
1748
1740
  currentSize = newSize;
1749
1741
  }
1750
- if (size.width !== newSize.width || size.height !== newSize.height) {
1742
+ if (sizeRef.current.width !== newSize.width || sizeRef.current.height !== newSize.height) {
1743
+ sizeRef.current = newSize;
1751
1744
  setSize(newSize);
1752
1745
  return newSize;
1753
1746
  }
1754
1747
  return null;
1755
- }, [size, setSize]);
1748
+ }, [setSize]);
1756
1749
  const onResize = react.useCallback(() => {
1757
1750
  const newSize = updateSize();
1758
1751
  if (newSize !== null && onChange !== null) {
@@ -1825,18 +1818,21 @@ const getWindowScroll = () => ({
1825
1818
  x: typeof window !== 'undefined' ? window.scrollX || 0 : 0,
1826
1819
  y: typeof window !== 'undefined' ? window.scrollY || 0 : 0
1827
1820
  });
1828
- const currentScroll = getWindowScroll();
1821
+ let currentScroll = getWindowScroll();
1829
1822
  function useWindowScroll() {
1830
1823
  let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1831
1824
  const {
1832
1825
  onChange = null
1833
1826
  } = opts;
1834
1827
  const [scroll, setScroll] = react.useState(currentScroll);
1828
+ const scrollRef = react.useRef(scroll);
1835
1829
  const updateScroll = react.useCallback(() => {
1836
1830
  const newScroll = getWindowScroll();
1837
1831
  if (currentScroll.x !== newScroll.x || currentScroll.y !== newScroll.y) {
1838
- currentScroll.x = newScroll.x;
1839
- currentScroll.y = newScroll.y;
1832
+ currentScroll = newScroll;
1833
+ }
1834
+ if (scrollRef.current.x !== newScroll.x || scrollRef.current.y !== newScroll.y) {
1835
+ scrollRef.current = newScroll;
1840
1836
  setScroll(newScroll);
1841
1837
  return newScroll;
1842
1838
  }
package/dist/es.js CHANGED
@@ -1731,17 +1731,19 @@ function useWindowSize() {
1731
1731
  onChange = null
1732
1732
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1733
1733
  const [size, setSize] = useState(currentSize);
1734
+ const sizeRef = useRef(size);
1734
1735
  const updateSize = useCallback(() => {
1735
1736
  const newSize = getWindowSize();
1736
1737
  if (currentSize.width !== newSize.width || currentSize.height !== newSize.height) {
1737
1738
  currentSize = newSize;
1738
1739
  }
1739
- if (size.width !== newSize.width || size.height !== newSize.height) {
1740
+ if (sizeRef.current.width !== newSize.width || sizeRef.current.height !== newSize.height) {
1741
+ sizeRef.current = newSize;
1740
1742
  setSize(newSize);
1741
1743
  return newSize;
1742
1744
  }
1743
1745
  return null;
1744
- }, [size, setSize]);
1746
+ }, [setSize]);
1745
1747
  const onResize = useCallback(() => {
1746
1748
  const newSize = updateSize();
1747
1749
  if (newSize !== null && onChange !== null) {
@@ -1814,18 +1816,21 @@ const getWindowScroll = () => ({
1814
1816
  x: typeof window !== 'undefined' ? window.scrollX || 0 : 0,
1815
1817
  y: typeof window !== 'undefined' ? window.scrollY || 0 : 0
1816
1818
  });
1817
- const currentScroll = getWindowScroll();
1819
+ let currentScroll = getWindowScroll();
1818
1820
  function useWindowScroll() {
1819
1821
  let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1820
1822
  const {
1821
1823
  onChange = null
1822
1824
  } = opts;
1823
1825
  const [scroll, setScroll] = useState(currentScroll);
1826
+ const scrollRef = useRef(scroll);
1824
1827
  const updateScroll = useCallback(() => {
1825
1828
  const newScroll = getWindowScroll();
1826
1829
  if (currentScroll.x !== newScroll.x || currentScroll.y !== newScroll.y) {
1827
- currentScroll.x = newScroll.x;
1828
- currentScroll.y = newScroll.y;
1830
+ currentScroll = newScroll;
1831
+ }
1832
+ if (scrollRef.current.x !== newScroll.x || scrollRef.current.y !== newScroll.y) {
1833
+ scrollRef.current = newScroll;
1829
1834
  setScroll(newScroll);
1830
1835
  return newScroll;
1831
1836
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/hooks",
3
- "version": "0.0.64",
3
+ "version": "0.0.66",
4
4
  "description": "React hooks",
5
5
  "keywords": [
6
6
  "javascript",
@@ -35,7 +35,7 @@
35
35
  "sideEffects": false,
36
36
  "scripts": {
37
37
  "clean": "rm -rf dist",
38
- "build": "rollup --config ../../rollup.config.js",
38
+ "build": "rollup --bundleConfigAsCjs --config ../../rollup.config.js",
39
39
  "prepare": "npm run clean && npm run build"
40
40
  },
41
41
  "devDependencies": {
@@ -49,10 +49,10 @@
49
49
  "publishConfig": {
50
50
  "access": "public"
51
51
  },
52
- "gitHead": "6b7ef9741a35f131038120725fe0ed79851eb216",
52
+ "gitHead": "c13ef70b8126b3182b3e3365f34f9231fa9b1535",
53
53
  "dependencies": {
54
- "@folklore/events": "^0.0.5",
55
- "@folklore/services": "^0.1.41",
54
+ "@folklore/events": "^0.0.6",
55
+ "@folklore/services": "^0.1.42",
56
56
  "cancelable-promise": "^4.3.1",
57
57
  "debug": "^4.3.4",
58
58
  "lodash": "^4.17.21",