{"version":3,"sources":["../../../src/react/enhancers/with-use-subscribe.ts"],"sourcesContent":["import { useSubscribe } from '../use-subscribe.js'\n\nimport type { SubscribeListener, VanillaStore } from '../../vanilla/index.js'\n\nexport interface WithUseSubscribeContributes<State extends object> {\n  /**\n   * Subscribes to the store state changes in React components.\n   *\n   * @param listener - The listener function.\n   * @param notifyInSync - Whether to notify the listener in sync.\n   */\n  useSubscribe: (listener: SubscribeListener<State>, notifyInSync?: boolean) => void\n}\n\n/**\n * Enhance a store with the `useSubscribe` methods.\n *\n * @param store - The store to be enhanced.\n * @returns The enhanced store.\n *\n * @since 0.2.0\n *\n * @example\n *\n * ```ts\n * import { createVanilla, withUseSubscribe } from '@reactive-react/core'\n *\n * const store = withUseSubscribe(createVanilla({ count: 0 }))\n *\n * // In a React component\n * store.useSubscribe((state) => {\n *  console.log(state.count)\n * })\n * ```\n *\n */\nexport function withUseSubscribe<Store extends VanillaStore<object>>(\n  store: Store\n): Store & WithUseSubscribeContributes<Store['mutate']> {\n  const boundUseSubscribe = (\n    listener: SubscribeListener<Store['mutate']>,\n    notifyInSync?: boolean\n  ) => {\n    return useSubscribe(store.mutate, listener, notifyInSync)\n  }\n\n  return {\n    ...store,\n    useSubscribe: boundUseSubscribe,\n  }\n}\n"],"names":["withUseSubscribe","store","boundUseSubscribe","listener","notifyInSync","useSubscribe","mutate"],"mappings":";;;;+BAoCgBA;;;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAT,SAASA,iBACdC,KAAY;IAEZ,IAAMC,oBAAoB,SACxBC,UACAC;QAEA,OAAOC,IAAAA,6BAAY,EAACJ,MAAMK,MAAM,EAAEH,UAAUC;IAC9C;IAEA,OAAO,wCACFH;QACHI,cAAcH;;AAElB"}