@etsoo/react 1.5.26 → 1.5.27
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/lib/uses/useDimensions.js +1 -25
- package/package.json +1 -1
- package/src/uses/useDimensions.ts +2 -31
|
@@ -49,6 +49,7 @@ export function useDimensions(elements, updateCallback, miliseconds = 50, equalC
|
|
|
49
49
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
50
50
|
// Update Rect
|
|
51
51
|
const indices = [];
|
|
52
|
+
const init = dimensions.current;
|
|
52
53
|
entries.forEach((entry) => {
|
|
53
54
|
const index = init.findIndex((item) => item[1] === entry.target);
|
|
54
55
|
if (index !== -1) {
|
|
@@ -78,31 +79,6 @@ export function useDimensions(elements, updateCallback, miliseconds = 50, equalC
|
|
|
78
79
|
delayed.call(undefined, update);
|
|
79
80
|
}
|
|
80
81
|
});
|
|
81
|
-
// Init
|
|
82
|
-
const init = [];
|
|
83
|
-
for (let e = 0; e < elements; e++) {
|
|
84
|
-
init.push(((index) => {
|
|
85
|
-
return [
|
|
86
|
-
(instance) => {
|
|
87
|
-
if (instance != null) {
|
|
88
|
-
// Current element
|
|
89
|
-
const currentElement = init[index][1];
|
|
90
|
-
if (currentElement != null) {
|
|
91
|
-
// Same target, return
|
|
92
|
-
if (currentElement == instance)
|
|
93
|
-
return;
|
|
94
|
-
// Cancel observation
|
|
95
|
-
resizeObserver.unobserve(currentElement);
|
|
96
|
-
}
|
|
97
|
-
// Update element
|
|
98
|
-
init[index][1] = instance;
|
|
99
|
-
// Start observe
|
|
100
|
-
resizeObserver.observe(instance);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
];
|
|
104
|
-
})(e));
|
|
105
|
-
}
|
|
106
82
|
// Layout ready
|
|
107
83
|
React.useEffect(() => {
|
|
108
84
|
return () => {
|
package/package.json
CHANGED
|
@@ -72,6 +72,8 @@ export function useDimensions(
|
|
|
72
72
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
73
73
|
// Update Rect
|
|
74
74
|
const indices: number[] = [];
|
|
75
|
+
const init = dimensions.current!;
|
|
76
|
+
|
|
75
77
|
entries.forEach((entry) => {
|
|
76
78
|
const index = init.findIndex((item) => item[1] === entry.target);
|
|
77
79
|
if (index !== -1) {
|
|
@@ -107,37 +109,6 @@ export function useDimensions(
|
|
|
107
109
|
}
|
|
108
110
|
});
|
|
109
111
|
|
|
110
|
-
// Init
|
|
111
|
-
const init: [React.RefCallback<Element>, Element?, DOMRect?][] = [];
|
|
112
|
-
for (let e = 0; e < elements; e++) {
|
|
113
|
-
init.push(
|
|
114
|
-
((index): [React.RefCallback<Element>] => {
|
|
115
|
-
return [
|
|
116
|
-
(instance) => {
|
|
117
|
-
if (instance != null) {
|
|
118
|
-
// Current element
|
|
119
|
-
const currentElement = init[index][1];
|
|
120
|
-
|
|
121
|
-
if (currentElement != null) {
|
|
122
|
-
// Same target, return
|
|
123
|
-
if (currentElement == instance) return;
|
|
124
|
-
|
|
125
|
-
// Cancel observation
|
|
126
|
-
resizeObserver.unobserve(currentElement);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Update element
|
|
130
|
-
init[index][1] = instance;
|
|
131
|
-
|
|
132
|
-
// Start observe
|
|
133
|
-
resizeObserver.observe(instance);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
];
|
|
137
|
-
})(e)
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
112
|
// Layout ready
|
|
142
113
|
React.useEffect(() => {
|
|
143
114
|
return () => {
|