{
  "version": 3,
  "sources": ["../../../../src/specialized-waitables/const-waitable/const-waitable.ts"],
  "sourcesContent": ["import { makeBinding, makeConstBinding, makeTransientDerivedBinding, useStableValue } from 'react-bindings';\n\nimport { waitForBindingValues } from '../../use-waitable/internal/wait-for-binding-values.mjs';\nimport type { WaitOptions } from '../../waitable/types/wait.mjs';\nimport type { Waitable } from '../../waitable/types/waitable.mjs';\nimport type { WrappedResult } from '../../waitable/types/wrapped-result.mjs';\n\nexport const makeConstWaitable = <SuccessT, FailureT = any>({\n  id,\n  value: successValue,\n  error: errorValue\n}: {\n  id: string;\n  value?: SuccessT;\n  error?: FailureT;\n}): Waitable<SuccessT, FailureT> => {\n  const force = makeBinding<WrappedResult<SuccessT, FailureT> | undefined>(() => undefined, { id: 'force' });\n\n  const error = makeTransientDerivedBinding(\n    force,\n    (force): FailureT | undefined => (force === undefined ? errorValue : force.ok ? undefined : force.value),\n    { id: 'error' }\n  );\n  const value = makeTransientDerivedBinding(\n    force,\n    (force): SuccessT | undefined => (force === undefined ? successValue : force.ok ? force.value : undefined),\n    { id: 'value' }\n  );\n\n  /**\n   * If true, either the `value` or `error` binding have defined values.\n   *\n   * This is a transient derived binding because we want it to have an up-to-date value, even when unmounted (since default value updates to\n   * value, for example, can happen asynchronously while unmounted).\n   */\n  const isComplete = makeTransientDerivedBinding(\n    { error, value },\n    ({ error, value }): boolean => value !== undefined || error !== undefined,\n    { id: `${id}_isComplete` }\n  );\n\n  const resetCount = makeConstBinding(0, { id: 'resetCount' });\n  const isBusy = makeConstBinding(false, { id: 'isBusy' });\n  const isLocked = makeConstBinding(false, { id: 'isLocked' });\n  const isLockedWithoutValue = makeConstBinding(false, { id: 'isLockedWithoutValue' });\n\n  return {\n    id,\n    error,\n    value,\n    isBusy,\n    isComplete,\n    isLocked,\n    isLockedWithoutValue,\n    isWaitable: true,\n    reset: () => {},\n    force,\n    wait: async (options?: WaitOptions) => waitForBindingValues({ error, resetCount, value, ...options })\n  };\n};\n\nexport const useConstWaitable = <SuccessT, FailureT = any>(args: {\n  id: string;\n  value?: SuccessT;\n  error?: FailureT;\n}): Waitable<SuccessT, FailureT> => useStableValue(makeConstWaitable<SuccessT, FailureT>(args));\n"],
  "mappings": "AAAA,SAAS,aAAa,kBAAkB,6BAA6B,sBAAsB;AAE3F,SAAS,4BAA4B;AAK9B,MAAM,oBAAoB,CAA2B;AAAA,EAC1D;AAAA,EACA,OAAO;AAAA,EACP,OAAO;AACT,MAIoC;AAClC,QAAM,QAAQ,YAA2D,MAAM,QAAW,EAAE,IAAI,QAAQ,CAAC;AAEzG,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA,CAACA,WAAiCA,WAAU,SAAY,aAAaA,OAAM,KAAK,SAAYA,OAAM;AAAA,IAClG,EAAE,IAAI,QAAQ;AAAA,EAChB;AACA,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA,CAACA,WAAiCA,WAAU,SAAY,eAAeA,OAAM,KAAKA,OAAM,QAAQ;AAAA,IAChG,EAAE,IAAI,QAAQ;AAAA,EAChB;AAQA,QAAM,aAAa;AAAA,IACjB,EAAE,OAAO,MAAM;AAAA,IACf,CAAC,EAAE,OAAAC,QAAO,OAAAC,OAAM,MAAeA,WAAU,UAAaD,WAAU;AAAA,IAChE,EAAE,IAAI,GAAG,EAAE,cAAc;AAAA,EAC3B;AAEA,QAAM,aAAa,iBAAiB,GAAG,EAAE,IAAI,aAAa,CAAC;AAC3D,QAAM,SAAS,iBAAiB,OAAO,EAAE,IAAI,SAAS,CAAC;AACvD,QAAM,WAAW,iBAAiB,OAAO,EAAE,IAAI,WAAW,CAAC;AAC3D,QAAM,uBAAuB,iBAAiB,OAAO,EAAE,IAAI,uBAAuB,CAAC;AAEnF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,OAAO,MAAM;AAAA,IAAC;AAAA,IACd;AAAA,IACA,MAAM,OAAO,YAA0B,qBAAqB,EAAE,OAAO,YAAY,OAAO,GAAG,QAAQ,CAAC;AAAA,EACtG;AACF;AAEO,MAAM,mBAAmB,CAA2B,SAIvB,eAAe,kBAAsC,IAAI,CAAC;",
  "names": ["force", "error", "value"]
}
