@folklore/hooks 0.0.81 → 0.0.82
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 +32 -13
- package/dist/es.js +32 -13
- package/package.json +2 -2
package/dist/cjs.js
CHANGED
|
@@ -1081,15 +1081,23 @@ const getWindowSize = () => ({
|
|
|
1081
1081
|
width: typeof window !== 'undefined' ? window.innerWidth || 0 : 0,
|
|
1082
1082
|
height: typeof window !== 'undefined' ? window.innerHeight || 0 : 0
|
|
1083
1083
|
});
|
|
1084
|
-
let currentSize =
|
|
1084
|
+
let currentSize = null;
|
|
1085
1085
|
function useWindowSize({
|
|
1086
|
-
onChange = null
|
|
1086
|
+
onChange = null,
|
|
1087
|
+
onMount = false,
|
|
1088
|
+
memo = false
|
|
1087
1089
|
} = {}) {
|
|
1088
|
-
const [size, setSize] = react.useState(
|
|
1090
|
+
const [size, setSize] = react.useState(onMount ? getWindowSize() : {
|
|
1091
|
+
width: 0,
|
|
1092
|
+
height: 0
|
|
1093
|
+
});
|
|
1089
1094
|
const sizeRef = react.useRef(size);
|
|
1095
|
+
if (currentSize === null && memo) {
|
|
1096
|
+
currentSize = size;
|
|
1097
|
+
}
|
|
1090
1098
|
const updateSize = react.useCallback(() => {
|
|
1091
1099
|
const newSize = getWindowSize();
|
|
1092
|
-
if (currentSize.width !== newSize.width || currentSize.height !== newSize.height) {
|
|
1100
|
+
if (memo && (currentSize.width !== newSize.width || currentSize.height !== newSize.height)) {
|
|
1093
1101
|
currentSize = newSize;
|
|
1094
1102
|
}
|
|
1095
1103
|
if (sizeRef.current.width !== newSize.width || sizeRef.current.height !== newSize.height) {
|
|
@@ -1098,7 +1106,7 @@ function useWindowSize({
|
|
|
1098
1106
|
return newSize;
|
|
1099
1107
|
}
|
|
1100
1108
|
return null;
|
|
1101
|
-
}, [setSize]);
|
|
1109
|
+
}, [setSize, memo]);
|
|
1102
1110
|
const onResize = react.useCallback(() => {
|
|
1103
1111
|
const newSize = updateSize();
|
|
1104
1112
|
if (newSize !== null && onChange !== null) {
|
|
@@ -1883,16 +1891,27 @@ const getWindowScroll = () => ({
|
|
|
1883
1891
|
x: typeof window !== 'undefined' ? window.scrollX || 0 : 0,
|
|
1884
1892
|
y: typeof window !== 'undefined' ? window.scrollY || 0 : 0
|
|
1885
1893
|
});
|
|
1886
|
-
let currentScroll =
|
|
1887
|
-
function useWindowScroll(
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1894
|
+
let currentScroll = null;
|
|
1895
|
+
function useWindowScroll({
|
|
1896
|
+
onChange = null,
|
|
1897
|
+
onMount = false,
|
|
1898
|
+
memo = false
|
|
1899
|
+
} = {}) {
|
|
1900
|
+
const [scroll, setScroll] = react.useState(onMount ? getWindowScroll() : {
|
|
1901
|
+
x: 0,
|
|
1902
|
+
y: 0
|
|
1903
|
+
});
|
|
1892
1904
|
const scrollRef = react.useRef(scroll);
|
|
1905
|
+
if (currentScroll === null && memo) {
|
|
1906
|
+
currentScroll = scroll;
|
|
1907
|
+
}
|
|
1893
1908
|
const updateScroll = react.useCallback(() => {
|
|
1894
1909
|
const newScroll = getWindowScroll();
|
|
1895
|
-
|
|
1910
|
+
const {
|
|
1911
|
+
x: currentX,
|
|
1912
|
+
y: currentY
|
|
1913
|
+
} = currentScroll || {};
|
|
1914
|
+
if (memo && (currentX !== newScroll.x || currentY !== newScroll.y)) {
|
|
1896
1915
|
currentScroll = newScroll;
|
|
1897
1916
|
}
|
|
1898
1917
|
if (scrollRef.current.x !== newScroll.x || scrollRef.current.y !== newScroll.y) {
|
|
@@ -1901,7 +1920,7 @@ function useWindowScroll(opts = {}) {
|
|
|
1901
1920
|
return newScroll;
|
|
1902
1921
|
}
|
|
1903
1922
|
return null;
|
|
1904
|
-
}, [setScroll]);
|
|
1923
|
+
}, [setScroll, memo]);
|
|
1905
1924
|
const onScroll = react.useCallback(() => {
|
|
1906
1925
|
const newScroll = updateScroll();
|
|
1907
1926
|
if (newScroll !== null && onChange !== null) {
|
package/dist/es.js
CHANGED
|
@@ -1079,15 +1079,23 @@ const getWindowSize = () => ({
|
|
|
1079
1079
|
width: typeof window !== 'undefined' ? window.innerWidth || 0 : 0,
|
|
1080
1080
|
height: typeof window !== 'undefined' ? window.innerHeight || 0 : 0
|
|
1081
1081
|
});
|
|
1082
|
-
let currentSize =
|
|
1082
|
+
let currentSize = null;
|
|
1083
1083
|
function useWindowSize({
|
|
1084
|
-
onChange = null
|
|
1084
|
+
onChange = null,
|
|
1085
|
+
onMount = false,
|
|
1086
|
+
memo = false
|
|
1085
1087
|
} = {}) {
|
|
1086
|
-
const [size, setSize] = useState(
|
|
1088
|
+
const [size, setSize] = useState(onMount ? getWindowSize() : {
|
|
1089
|
+
width: 0,
|
|
1090
|
+
height: 0
|
|
1091
|
+
});
|
|
1087
1092
|
const sizeRef = useRef(size);
|
|
1093
|
+
if (currentSize === null && memo) {
|
|
1094
|
+
currentSize = size;
|
|
1095
|
+
}
|
|
1088
1096
|
const updateSize = useCallback(() => {
|
|
1089
1097
|
const newSize = getWindowSize();
|
|
1090
|
-
if (currentSize.width !== newSize.width || currentSize.height !== newSize.height) {
|
|
1098
|
+
if (memo && (currentSize.width !== newSize.width || currentSize.height !== newSize.height)) {
|
|
1091
1099
|
currentSize = newSize;
|
|
1092
1100
|
}
|
|
1093
1101
|
if (sizeRef.current.width !== newSize.width || sizeRef.current.height !== newSize.height) {
|
|
@@ -1096,7 +1104,7 @@ function useWindowSize({
|
|
|
1096
1104
|
return newSize;
|
|
1097
1105
|
}
|
|
1098
1106
|
return null;
|
|
1099
|
-
}, [setSize]);
|
|
1107
|
+
}, [setSize, memo]);
|
|
1100
1108
|
const onResize = useCallback(() => {
|
|
1101
1109
|
const newSize = updateSize();
|
|
1102
1110
|
if (newSize !== null && onChange !== null) {
|
|
@@ -1881,16 +1889,27 @@ const getWindowScroll = () => ({
|
|
|
1881
1889
|
x: typeof window !== 'undefined' ? window.scrollX || 0 : 0,
|
|
1882
1890
|
y: typeof window !== 'undefined' ? window.scrollY || 0 : 0
|
|
1883
1891
|
});
|
|
1884
|
-
let currentScroll =
|
|
1885
|
-
function useWindowScroll(
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1892
|
+
let currentScroll = null;
|
|
1893
|
+
function useWindowScroll({
|
|
1894
|
+
onChange = null,
|
|
1895
|
+
onMount = false,
|
|
1896
|
+
memo = false
|
|
1897
|
+
} = {}) {
|
|
1898
|
+
const [scroll, setScroll] = useState(onMount ? getWindowScroll() : {
|
|
1899
|
+
x: 0,
|
|
1900
|
+
y: 0
|
|
1901
|
+
});
|
|
1890
1902
|
const scrollRef = useRef(scroll);
|
|
1903
|
+
if (currentScroll === null && memo) {
|
|
1904
|
+
currentScroll = scroll;
|
|
1905
|
+
}
|
|
1891
1906
|
const updateScroll = useCallback(() => {
|
|
1892
1907
|
const newScroll = getWindowScroll();
|
|
1893
|
-
|
|
1908
|
+
const {
|
|
1909
|
+
x: currentX,
|
|
1910
|
+
y: currentY
|
|
1911
|
+
} = currentScroll || {};
|
|
1912
|
+
if (memo && (currentX !== newScroll.x || currentY !== newScroll.y)) {
|
|
1894
1913
|
currentScroll = newScroll;
|
|
1895
1914
|
}
|
|
1896
1915
|
if (scrollRef.current.x !== newScroll.x || scrollRef.current.y !== newScroll.y) {
|
|
@@ -1899,7 +1918,7 @@ function useWindowScroll(opts = {}) {
|
|
|
1899
1918
|
return newScroll;
|
|
1900
1919
|
}
|
|
1901
1920
|
return null;
|
|
1902
|
-
}, [setScroll]);
|
|
1921
|
+
}, [setScroll, memo]);
|
|
1903
1922
|
const onScroll = useCallback(() => {
|
|
1904
1923
|
const newScroll = updateScroll();
|
|
1905
1924
|
if (newScroll !== null && onChange !== null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.82",
|
|
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": "565254f67e63bf9f1ccb4ef925633af37682e44d",
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@folklore/events": "^0.0.10",
|
|
55
55
|
"@folklore/services": "^0.1.44",
|