@folklore/hooks 0.0.40 → 0.0.42

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 +17 -8
  2. package/dist/es.js +17 -8
  3. package/package.json +2 -2
package/dist/cjs.js CHANGED
@@ -19,16 +19,24 @@ var isNumber__default = /*#__PURE__*/_interopDefaultLegacy(isNumber);
19
19
 
20
20
  function useCounter(desiredValue, _ref) {
21
21
  let {
22
+ disabled = false,
22
23
  maxDuration = 2000,
23
- speed = 1 / 10
24
+ speed = 1 / 10,
25
+ initialValue = null
24
26
  } = _ref;
25
- const [currentValue, setCurrentValue] = react.useState(desiredValue);
27
+ const [currentValue, setCurrentValue] = react.useState(initialValue !== null ? initialValue : desiredValue);
28
+ react.useEffect(() => {
29
+ if (initialValue !== null && !disabled) {
30
+ setCurrentValue(initialValue);
31
+ }
32
+ }, [initialValue, disabled]);
26
33
  react.useEffect(() => {
34
+ const finalCurrentValue = disabled ? desiredValue : currentValue;
27
35
  let animationFrame = null;
28
36
  let startTime = null;
29
37
  let duration = 0;
30
38
  let canceled = false;
31
- const startValue = currentValue;
39
+ const startValue = finalCurrentValue;
32
40
  const delta = desiredValue - startValue;
33
41
  function loop() {
34
42
  if (canceled) {
@@ -47,6 +55,8 @@ function useCounter(desiredValue, _ref) {
47
55
  duration = Math.min(maxDuration, Math.abs(delta) * speed * 1000);
48
56
  startTime = Date.now();
49
57
  animationFrame = raf__default["default"](loop);
58
+ } else if (disabled) {
59
+ setCurrentValue(desiredValue);
50
60
  }
51
61
  return () => {
52
62
  canceled = true;
@@ -54,7 +64,7 @@ function useCounter(desiredValue, _ref) {
54
64
  raf__default["default"].cancel(animationFrame);
55
65
  }
56
66
  };
57
- }, [desiredValue]);
67
+ }, [desiredValue, disabled, initialValue, maxDuration, speed]);
58
68
  return currentValue;
59
69
  }
60
70
 
@@ -1535,6 +1545,9 @@ function useYouTubePlayer(id) {
1535
1545
  });
1536
1546
  }
1537
1547
  debug('onReady [ID: %s]', videoId);
1548
+ if (muted) {
1549
+ player.mute();
1550
+ }
1538
1551
  };
1539
1552
  const onStateChange = _ref2 => {
1540
1553
  let {
@@ -1660,13 +1673,11 @@ function useVideoPlayer(params) {
1660
1673
  customOnPlay();
1661
1674
  }
1662
1675
  }, [playing /* , customOnPlay */]);
1663
-
1664
1676
  react.useEffect(() => {
1665
1677
  if (paused && customOnPause !== null) {
1666
1678
  customOnPause();
1667
1679
  }
1668
1680
  }, [paused /* , customOnPause */]);
1669
-
1670
1681
  react.useEffect(() => {
1671
1682
  if (buffering && customOnBufferStart !== null) {
1672
1683
  customOnBufferStart();
@@ -1674,13 +1685,11 @@ function useVideoPlayer(params) {
1674
1685
  customOnBufferEnded();
1675
1686
  }
1676
1687
  }, [buffering /* , customOnBufferStart, customOnBufferEnded */]);
1677
-
1678
1688
  react.useEffect(() => {
1679
1689
  if (ended && customOnEnd !== null) {
1680
1690
  customOnEnd();
1681
1691
  }
1682
1692
  }, [ended /* , customOnEnd */]);
1683
-
1684
1693
  react.useEffect(() => {
1685
1694
  const hasMetadata = metaWidth !== null || metaHeight !== null || metaDuration !== null;
1686
1695
  if (hasMetadata && customOnMetadataChange !== null) {
package/dist/es.js CHANGED
@@ -8,16 +8,24 @@ import isNumber from 'lodash/isNumber';
8
8
 
9
9
  function useCounter(desiredValue, _ref) {
10
10
  let {
11
+ disabled = false,
11
12
  maxDuration = 2000,
12
- speed = 1 / 10
13
+ speed = 1 / 10,
14
+ initialValue = null
13
15
  } = _ref;
14
- const [currentValue, setCurrentValue] = useState(desiredValue);
16
+ const [currentValue, setCurrentValue] = useState(initialValue !== null ? initialValue : desiredValue);
17
+ useEffect(() => {
18
+ if (initialValue !== null && !disabled) {
19
+ setCurrentValue(initialValue);
20
+ }
21
+ }, [initialValue, disabled]);
15
22
  useEffect(() => {
23
+ const finalCurrentValue = disabled ? desiredValue : currentValue;
16
24
  let animationFrame = null;
17
25
  let startTime = null;
18
26
  let duration = 0;
19
27
  let canceled = false;
20
- const startValue = currentValue;
28
+ const startValue = finalCurrentValue;
21
29
  const delta = desiredValue - startValue;
22
30
  function loop() {
23
31
  if (canceled) {
@@ -36,6 +44,8 @@ function useCounter(desiredValue, _ref) {
36
44
  duration = Math.min(maxDuration, Math.abs(delta) * speed * 1000);
37
45
  startTime = Date.now();
38
46
  animationFrame = raf(loop);
47
+ } else if (disabled) {
48
+ setCurrentValue(desiredValue);
39
49
  }
40
50
  return () => {
41
51
  canceled = true;
@@ -43,7 +53,7 @@ function useCounter(desiredValue, _ref) {
43
53
  raf.cancel(animationFrame);
44
54
  }
45
55
  };
46
- }, [desiredValue]);
56
+ }, [desiredValue, disabled, initialValue, maxDuration, speed]);
47
57
  return currentValue;
48
58
  }
49
59
 
@@ -1524,6 +1534,9 @@ function useYouTubePlayer(id) {
1524
1534
  });
1525
1535
  }
1526
1536
  debug('onReady [ID: %s]', videoId);
1537
+ if (muted) {
1538
+ player.mute();
1539
+ }
1527
1540
  };
1528
1541
  const onStateChange = _ref2 => {
1529
1542
  let {
@@ -1649,13 +1662,11 @@ function useVideoPlayer(params) {
1649
1662
  customOnPlay();
1650
1663
  }
1651
1664
  }, [playing /* , customOnPlay */]);
1652
-
1653
1665
  useEffect(() => {
1654
1666
  if (paused && customOnPause !== null) {
1655
1667
  customOnPause();
1656
1668
  }
1657
1669
  }, [paused /* , customOnPause */]);
1658
-
1659
1670
  useEffect(() => {
1660
1671
  if (buffering && customOnBufferStart !== null) {
1661
1672
  customOnBufferStart();
@@ -1663,13 +1674,11 @@ function useVideoPlayer(params) {
1663
1674
  customOnBufferEnded();
1664
1675
  }
1665
1676
  }, [buffering /* , customOnBufferStart, customOnBufferEnded */]);
1666
-
1667
1677
  useEffect(() => {
1668
1678
  if (ended && customOnEnd !== null) {
1669
1679
  customOnEnd();
1670
1680
  }
1671
1681
  }, [ended /* , customOnEnd */]);
1672
-
1673
1682
  useEffect(() => {
1674
1683
  const hasMetadata = metaWidth !== null || metaHeight !== null || metaDuration !== null;
1675
1684
  if (hasMetadata && customOnMetadataChange !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/hooks",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "description": "React hooks",
5
5
  "keywords": [
6
6
  "javascript",
@@ -49,7 +49,7 @@
49
49
  "publishConfig": {
50
50
  "access": "public"
51
51
  },
52
- "gitHead": "cdf211231eecfb77f442f81af2b300c7dd78b6d7",
52
+ "gitHead": "e1d76c01312a1d1556483e08d171f595a89016e4",
53
53
  "dependencies": {
54
54
  "@folklore/events": "^0.0.5",
55
55
  "@folklore/services": "^0.1.38",