{"version":3,"file":"ngxtension-inject-destroy.mjs","sources":["../../../../libs/ngxtension/inject-destroy/src/inject-destroy.ts","../../../../libs/ngxtension/inject-destroy/src/ngxtension-inject-destroy.ts"],"sourcesContent":["import {\n\tDestroyRef,\n\tinject,\n\trunInInjectionContext,\n\ttype Injector,\n} from '@angular/core';\nimport { assertInjector } from 'ngxtension/assert-injector';\nimport { ReplaySubject } from 'rxjs';\n\n/**\n * Injects the `DestroyRef` service and returns a `ReplaySubject` that emits\n * when the component is destroyed.\n *\n * @throws {Error} If no `DestroyRef` is found.\n * @returns {ReplaySubject<void>} A `ReplaySubject` that emits when the component is destroyed.\n *\n * @example\n * // In your component:\n * export class MyComponent {\n *   private destroy$ = injectDestroy();\n *\n *   getData() {\n *     return this.service.getData()\n *       .pipe(takeUntil(this.destroy$))\n *       .subscribe(data => { ... });\n *   }\n * }\n */\nexport const injectDestroy = (\n\tinjector?: Injector,\n): ReplaySubject<void> & { onDestroy: DestroyRef['onDestroy'] } => {\n\tinjector = assertInjector(injectDestroy, injector);\n\n\treturn runInInjectionContext(injector, () => {\n\t\tconst destroyRef = inject(DestroyRef);\n\n\t\tconst subject$ = new ReplaySubject<void>(1);\n\n\t\tdestroyRef.onDestroy(() => {\n\t\t\tsubject$.next();\n\t\t\tsubject$.complete();\n\t\t});\n\n\t\tObject.assign(subject$, {\n\t\t\tonDestroy: destroyRef.onDestroy.bind(destroyRef),\n\t\t});\n\n\t\treturn subject$ as ReplaySubject<void> & {\n\t\t\tonDestroy: DestroyRef['onDestroy'];\n\t\t};\n\t});\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AASA;;;;;;;;;;;;;;;;;;AAkBG;AACU,MAAA,aAAa,GAAG,CAC5B,QAAmB,KAC8C;AACjE,IAAA,QAAQ,GAAG,cAAc,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;AAEnD,IAAA,OAAO,qBAAqB,CAAC,QAAQ,EAAE,MAAK;AAC3C,QAAA,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAEtC,QAAA,MAAM,QAAQ,GAAG,IAAI,aAAa,CAAO,CAAC,CAAC,CAAC;AAE5C,QAAA,UAAU,CAAC,SAAS,CAAC,MAAK;YACzB,QAAQ,CAAC,IAAI,EAAE,CAAC;YAChB,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACrB,SAAC,CAAC,CAAC;AAEH,QAAA,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;YACvB,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;AAChD,SAAA,CAAC,CAAC;AAEH,QAAA,OAAO,QAEN,CAAC;AACH,KAAC,CAAC,CAAC;AACJ;;ACnDA;;AAEG;;;;"}