{"version":3,"names":["createEffect","untrack","useValueChanged","value","onChange","primed","next","prev","Object","is"],"sources":["use-value-changed.ts"],"sourcesContent":["import { type Accessor, createEffect, untrack } from \"solid-js\";\n\n/**\n * Fires `onChange(next, previous)` whenever the tracked value changes by\n * identity. Mirrors Base UI React's `useValueChanged`\n * (`packages/react/src/internals/useValueChanged.ts`).\n *\n * The value must be provided as a reactive accessor. In Solid 2, change\n * detection maps naturally to the split-effect form: the compute half returns\n * the current value, and the apply half receives both the new compute return\n * and the prior one. We carry a \"first run\" latch so the callback isn't\n * fired on initial setup (matching React — its first effect pass sees\n * `valueRef.current === value` because both came from the same render).\n *\n * The callback runs inside `untrack` so it can call into other accessors\n * (`field.shouldValidateOnChange()`, `name()`, etc.) without tripping\n * `[STRICT_READ_UNTRACKED]`. Side-effect callbacks read snapshots, they\n * don't subscribe — re-runs are driven by the tracked `value` accessor\n * passed as the first argument.\n *\n * @param value Accessor for the tracked value.\n * @param onChange Called with `(next, previous)` whenever `value()` changes.\n *                 Most callers ignore `previous` — accept it positionally if\n *                 you need to compare the transition.\n */\nexport function useValueChanged<T>(\n\tvalue: Accessor<T>,\n\tonChange: (next: T, previous: T) => void,\n): void {\n\t// Closure latch — flipped true after the effect's first apply so\n\t// subsequent runs fire `onChange`. Declared before `createEffect` so the\n\t// apply closure doesn't reference a let-binding that is textually below\n\t// its own declaration (TDZ-safe today because apply is async, but it's\n\t// fragile — keeping the declaration above is clearer).\n\tlet primed = false;\n\tcreateEffect(\n\t\t// The compute phase just tracks `value()`; its return is also what\n\t\t// Solid forwards as `prev` on the next run.\n\t\t() => value(),\n\t\t(next, prev) => {\n\t\t\t// `prev` is undefined on the first run (Solid 2 split-effect\n\t\t\t// semantics). But `undefined` is a legitimate `T` value for some\n\t\t\t// callers, so we use a separate latch instead of checking `prev`.\n\t\t\tif (!primed) {\n\t\t\t\tprimed = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!Object.is(next, prev as T)) {\n\t\t\t\tuntrack(() => onChange(next, prev as T));\n\t\t\t}\n\t\t},\n\t);\n}\n"],"mappings":"AAAA,SAAwBA,YAAY,EAAEC,OAAO,QAAQ,UAAU;;AAE/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC9BC,KAAkB,EAClBC,QAAwC,EACjC;EACP;EACA;EACA;EACA;EACA;EACA,IAAIC,MAAM,GAAG,KAAK;EAClBL,YAAY;EACX;EACA;EACA,MAAMG,KAAK,CAAC,CAAC,EACb,CAACG,IAAI,EAAEC,IAAI,KAAK;IACf;IACA;IACA;IACA,IAAI,CAACF,MAAM,EAAE;MACZA,MAAM,GAAG,IAAI;MACb;IACD;IACA,IAAI,CAACG,MAAM,CAACC,EAAE,CAACH,IAAI,EAAEC,IAAS,CAAC,EAAE;MAChCN,OAAO,CAAC,MAAMG,QAAQ,CAACE,IAAI,EAAEC,IAAS,CAAC,CAAC;IACzC;EACD,CACD,CAAC;AACF","ignoreList":[]}