codigo0/node_modules/use-callback-ref/dist/es2019/refToCallback.js
planetazuzu 5d7a6500fe refactor: Fase 1 - Clean Architecture, refactorización modular y eliminación de duplicidades
-  Ticket 1.1: Estructura Clean Architecture en backend
-  Ticket 1.2: Schemas Zod compartidos
-  Ticket 1.3: Refactorización drugs.ts (1362 → 8 archivos modulares)
-  Ticket 1.4: Refactorización procedures.ts (3583 → 6 archivos modulares)
-  Ticket 1.5: Eliminación de duplicidades (~50 líneas)

Cambios principales:
- Creada estructura Clean Architecture en backend/src/
- Schemas Zod compartidos en backend/src/shared/schemas/
- Refactorización modular de drugs y procedures
- Utilidades genéricas en src/utils/ (filter, validation)
- Eliminados scripts obsoletos y documentación antigua
- Corregidos errores: QueryClient, import test-error-handling
- Build verificado y funcionando correctamente
2026-01-25 21:09:47 +01:00

49 lines
1.2 KiB
JavaScript

/**
* Unmemoized version of {@link useRefToCallback}
* @see {@link useRefToCallback}
* @param ref
*/
export function refToCallback(ref) {
return (newValue) => {
if (typeof ref === 'function') {
ref(newValue);
}
else if (ref) {
ref.current = newValue;
}
};
}
const nullCallback = () => null;
// lets maintain a weak ref to, well, ref :)
// not using `kashe` to keep this package small
const weakMem = new WeakMap();
const weakMemoize = (ref) => {
const usedRef = ref || nullCallback;
const storedRef = weakMem.get(usedRef);
if (storedRef) {
return storedRef;
}
const cb = refToCallback(usedRef);
weakMem.set(usedRef, cb);
return cb;
};
/**
* Transforms a given `ref` into `callback`.
*
* To transform `callback` into ref use {@link useCallbackRef|useCallbackRef(undefined, callback)}
*
* @param {ReactRef} ref
* @returns {Function}
*
* @see https://github.com/theKashey/use-callback-ref#reftocallback
*
* @example
* const ref = useRef(0);
* const setRef = useRefToCallback(ref);
* 👉 setRef(10);
* ✅ ref.current === 10
*/
export function useRefToCallback(ref) {
return weakMemoize(ref);
}