{"version":3,"names":["createStableCallback","getCallback","trampoline","args","current"],"sources":["stable-callback.ts"],"sourcesContent":["/**\n * Stabilize a possibly-changing callback so that consumers get a referentially\n * stable function. In Solid, components don't re-render, so \"stability\" only\n * matters when a consumer captures the current callback into something with\n * its own identity (e.g. a directive, a long-lived subscription). This helper\n * returns a trampoline whose identity never changes; internally, it dispatches\n * to whatever `callback` is pointed at when invoked.\n *\n * Semantically equivalent to Base UI React's `useStableCallback`, adapted for\n * Solid's non-rerendering model: instead of keeping a ref synced inside a\n * layout effect, we mutate the stored callback on every call site so the\n * latest closure wins at invocation time.\n *\n * Important: only call the returned trampoline from event handlers, effects,\n * or other non-render code. Calling it synchronously during component setup\n * before the callback it wraps has been assigned is a bug.\n */\n/**\n * Structural supertype of every function shape users might stabilize. We\n * lean on `any` here because `unknown[]` wouldn't admit callbacks with\n * highly specific parameter signatures as subtypes, which would defeat the\n * purpose of this primitive.\n */\n// biome-ignore-start lint/suspicious/noExplicitAny: see type comment above.\nexport type AnyCallback = (...args: any[]) => any;\n// biome-ignore-end lint/suspicious/noExplicitAny: see type comment above.\n\nexport function createStableCallback<T extends AnyCallback>(\n\tgetCallback: () => T | undefined,\n): T {\n\tconst trampoline = ((...args: unknown[]) => {\n\t\tconst current = getCallback();\n\t\treturn current?.(...args);\n\t}) as T;\n\treturn trampoline;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,OAAO,SAASA,oBAAoBA,CACnCC,WAAgC,EAC5B;EACJ,MAAMC,UAAU,GAAIA,CAAC,GAAGC,IAAe,KAAK;IAC3C,MAAMC,OAAO,GAAGH,WAAW,CAAC,CAAC;IAC7B,OAAOG,OAAO,GAAG,GAAGD,IAAI,CAAC;EAC1B,CAAO;EACP,OAAOD,UAAU;AAClB","ignoreList":[]}