{"version":3,"file":"ngxtension-create-effect.mjs","sources":["../../../../libs/ngxtension/create-effect/src/create-effect.ts","../../../../libs/ngxtension/create-effect/src/ngxtension-create-effect.ts"],"sourcesContent":["import {\n\tDestroyRef,\n\tInjector,\n\tinject,\n\tisSignal,\n\trunInInjectionContext,\n\ttype Signal,\n} from '@angular/core';\nimport { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';\nimport { assertInjector } from 'ngxtension/assert-injector';\nimport {\n\tObservable,\n\tSubject,\n\tSubscription,\n\tisObservable,\n\tof,\n\tretry,\n\ttype RetryConfig,\n} from 'rxjs';\n\nexport type CreateEffectOptions = {\n\tinjector?: Injector;\n\t/**\n\t * @param retryOnError\n\t * Set to 'false' to disable retrying on error.\n\t * Otherwise, generated effect will use `retry()`.\n\t * You can pass `RetryConfig` object here to configure `retry()` operator.\n\t */\n\tretryOnError?: boolean | RetryConfig;\n};\n\n/**\n * This code is a copied `ComponentStore.effect()` method from NgRx and edited to:\n * 1) be a standalone function;\n * 2) use `takeUntilDestroyed()` with an injected `DestroyRef`;\n * 3) resubscribe on errors.\n *\n * Credits: NgRx Team\n * https://ngrx.io/\n * Source: https://github.com/ngrx/platform/blob/main/modules/component-store/src/component-store.ts#L382\n * Docs:\n * https://ngrx.io/guide/component-store/effect#effect-method\n */\nexport function createEffect<\n\tProvidedType = void,\n\tOriginType extends\n\t\t| Observable<ProvidedType>\n\t\t| unknown = Observable<ProvidedType>,\n\tObservableType = OriginType extends Observable<infer A> ? A : never,\n\tReturnType = ProvidedType | ObservableType extends void\n\t\t? (\n\t\t\t\tobservableOrValue?:\n\t\t\t\t\t| ObservableType\n\t\t\t\t\t| Observable<ObservableType>\n\t\t\t\t\t| Signal<ObservableType>,\n\t\t\t) => Subscription\n\t\t: (\n\t\t\t\tobservableOrValue:\n\t\t\t\t\t| ObservableType\n\t\t\t\t\t| Observable<ObservableType>\n\t\t\t\t\t| Signal<ObservableType>,\n\t\t\t) => Subscription,\n>(\n\tgenerator: (origin$: OriginType) => Observable<unknown>,\n\toptions?: CreateEffectOptions,\n): ReturnType {\n\tconst injector = assertInjector(createEffect, options?.injector);\n\treturn runInInjectionContext(injector, () => {\n\t\tconst destroyRef = inject(DestroyRef);\n\t\tconst origin$ = new Subject<ObservableType>();\n\t\tconst retryOnError = !!(options?.retryOnError ?? true);\n\t\tconst retryConfig =\n\t\t\ttypeof options?.retryOnError === 'object' && options?.retryOnError\n\t\t\t\t? options?.retryOnError\n\t\t\t\t: ({} as RetryConfig);\n\n\t\tif (retryOnError) {\n\t\t\tgenerator(origin$ as OriginType)\n\t\t\t\t.pipe(retry(retryConfig), takeUntilDestroyed(destroyRef))\n\t\t\t\t.subscribe();\n\t\t} else {\n\t\t\tgenerator(origin$ as OriginType)\n\t\t\t\t.pipe(takeUntilDestroyed(destroyRef))\n\t\t\t\t.subscribe();\n\t\t}\n\n\t\treturn ((\n\t\t\tobservableOrValue?: ObservableType | Observable<ObservableType>,\n\t\t): Subscription => {\n\t\t\tconst observable$ = isObservable(observableOrValue)\n\t\t\t\t? observableOrValue\n\t\t\t\t: isSignal(observableOrValue)\n\t\t\t\t\t? toObservable(observableOrValue, { injector })\n\t\t\t\t\t: of(observableOrValue);\n\t\t\tif (retryOnError) {\n\t\t\t\treturn observable$\n\t\t\t\t\t.pipe(retry(retryConfig), takeUntilDestroyed(destroyRef))\n\t\t\t\t\t.subscribe((value) => {\n\t\t\t\t\t\torigin$.next(value as ObservableType);\n\t\t\t\t\t});\n\t\t\t} else {\n\t\t\t\treturn observable$\n\t\t\t\t\t.pipe(takeUntilDestroyed(destroyRef))\n\t\t\t\t\t.subscribe((value) => {\n\t\t\t\t\t\torigin$.next(value as ObservableType);\n\t\t\t\t\t});\n\t\t\t}\n\t\t}) as unknown as ReturnType;\n\t});\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AA+BA;;;;;;;;;;;AAWG;AACa,SAAA,YAAY,CAoB3B,SAAuD,EACvD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