mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-22 05:11:55 +01:00
[Perf] Some optimizations
This commit is contained in:
parent
4e0f4d99e8
commit
3ac7711f17
@ -13,18 +13,18 @@ export default (
|
||||
const [isClosed, setIsClosed] = useState(!isOpen);
|
||||
const closeTimeoutRef = useRef<number>();
|
||||
// СSS class should be added in a separate tick to turn on CSS transition.
|
||||
const [hasAsyncOpenClassName, setHasAsyncOpenClassName] = useState(false);
|
||||
const [hasOpenClassName, setHasOpenClassName] = useState(isOpen && noOpenTransition);
|
||||
|
||||
if (isOpen) {
|
||||
setIsClosed(false);
|
||||
setHasAsyncOpenClassName(true);
|
||||
setHasOpenClassName(true);
|
||||
|
||||
if (closeTimeoutRef.current) {
|
||||
window.clearTimeout(closeTimeoutRef.current);
|
||||
closeTimeoutRef.current = undefined;
|
||||
}
|
||||
} else {
|
||||
setHasAsyncOpenClassName(false);
|
||||
setHasOpenClassName(false);
|
||||
|
||||
if (!isClosed && !closeTimeoutRef.current) {
|
||||
closeTimeoutRef.current = window.setTimeout(() => {
|
||||
@ -39,7 +39,6 @@ export default (
|
||||
}
|
||||
}
|
||||
|
||||
const hasOpenClassName = hasAsyncOpenClassName || (isOpen && noOpenTransition);
|
||||
const isClosing = Boolean(closeTimeoutRef.current);
|
||||
const shouldRender = isOpen || isClosing;
|
||||
const transitionClassNames = buildClassName(
|
||||
|
@ -1,4 +1,8 @@
|
||||
export default function arePropsShallowEqual(currentProps: AnyLiteral, newProps: AnyLiteral) {
|
||||
if (currentProps === newProps) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const currentKeys = Object.keys(currentProps);
|
||||
const currentKeysLength = currentKeys.length;
|
||||
const newKeysLength = Object.keys(newProps).length;
|
||||
@ -7,5 +11,16 @@ export default function arePropsShallowEqual(currentProps: AnyLiteral, newProps:
|
||||
return false;
|
||||
}
|
||||
|
||||
return currentKeys.every((prop) => currentProps[prop] === newProps[prop]);
|
||||
if (currentKeysLength === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (let i = 0; i < currentKeysLength; i++) {
|
||||
const prop = currentKeys[i];
|
||||
if (currentProps[prop] !== newProps[prop]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user