@folklore/hooks 0.0.41 → 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.
- package/dist/cjs.js +14 -8
- package/dist/es.js +14 -8
- 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 =
|
|
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
|
|
|
@@ -1663,13 +1673,11 @@ function useVideoPlayer(params) {
|
|
|
1663
1673
|
customOnPlay();
|
|
1664
1674
|
}
|
|
1665
1675
|
}, [playing /* , customOnPlay */]);
|
|
1666
|
-
|
|
1667
1676
|
react.useEffect(() => {
|
|
1668
1677
|
if (paused && customOnPause !== null) {
|
|
1669
1678
|
customOnPause();
|
|
1670
1679
|
}
|
|
1671
1680
|
}, [paused /* , customOnPause */]);
|
|
1672
|
-
|
|
1673
1681
|
react.useEffect(() => {
|
|
1674
1682
|
if (buffering && customOnBufferStart !== null) {
|
|
1675
1683
|
customOnBufferStart();
|
|
@@ -1677,13 +1685,11 @@ function useVideoPlayer(params) {
|
|
|
1677
1685
|
customOnBufferEnded();
|
|
1678
1686
|
}
|
|
1679
1687
|
}, [buffering /* , customOnBufferStart, customOnBufferEnded */]);
|
|
1680
|
-
|
|
1681
1688
|
react.useEffect(() => {
|
|
1682
1689
|
if (ended && customOnEnd !== null) {
|
|
1683
1690
|
customOnEnd();
|
|
1684
1691
|
}
|
|
1685
1692
|
}, [ended /* , customOnEnd */]);
|
|
1686
|
-
|
|
1687
1693
|
react.useEffect(() => {
|
|
1688
1694
|
const hasMetadata = metaWidth !== null || metaHeight !== null || metaDuration !== null;
|
|
1689
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 =
|
|
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
|
|
|
@@ -1652,13 +1662,11 @@ function useVideoPlayer(params) {
|
|
|
1652
1662
|
customOnPlay();
|
|
1653
1663
|
}
|
|
1654
1664
|
}, [playing /* , customOnPlay */]);
|
|
1655
|
-
|
|
1656
1665
|
useEffect(() => {
|
|
1657
1666
|
if (paused && customOnPause !== null) {
|
|
1658
1667
|
customOnPause();
|
|
1659
1668
|
}
|
|
1660
1669
|
}, [paused /* , customOnPause */]);
|
|
1661
|
-
|
|
1662
1670
|
useEffect(() => {
|
|
1663
1671
|
if (buffering && customOnBufferStart !== null) {
|
|
1664
1672
|
customOnBufferStart();
|
|
@@ -1666,13 +1674,11 @@ function useVideoPlayer(params) {
|
|
|
1666
1674
|
customOnBufferEnded();
|
|
1667
1675
|
}
|
|
1668
1676
|
}, [buffering /* , customOnBufferStart, customOnBufferEnded */]);
|
|
1669
|
-
|
|
1670
1677
|
useEffect(() => {
|
|
1671
1678
|
if (ended && customOnEnd !== null) {
|
|
1672
1679
|
customOnEnd();
|
|
1673
1680
|
}
|
|
1674
1681
|
}, [ended /* , customOnEnd */]);
|
|
1675
|
-
|
|
1676
1682
|
useEffect(() => {
|
|
1677
1683
|
const hasMetadata = metaWidth !== null || metaHeight !== null || metaDuration !== null;
|
|
1678
1684
|
if (hasMetadata && customOnMetadataChange !== null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/hooks",
|
|
3
|
-
"version": "0.0.
|
|
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": "
|
|
52
|
+
"gitHead": "e1d76c01312a1d1556483e08d171f595a89016e4",
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@folklore/events": "^0.0.5",
|
|
55
55
|
"@folklore/services": "^0.1.38",
|