{"version":3,"sources":["node_modules/ngxtension/fesm2022/ngxtension-assert-injector.mjs","node_modules/ngxtension/fesm2022/ngxtension-derived-async.mjs"],"sourcesContent":["import { assertInInjectionContext, inject, Injector, runInInjectionContext } from '@angular/core';\nfunction assertInjector(fn, injector, runner) {\n !injector && assertInInjectionContext(fn);\n const assertedInjector = injector ?? inject(Injector);\n if (!runner) return assertedInjector;\n return runInInjectionContext(assertedInjector, runner);\n}\n\n/**\n * Generated bundle index. Do not edit.\n */\n\nexport { assertInjector };\n","import { inject, DestroyRef, signal, effect, untracked, computed } from '@angular/core';\nimport { assertInjector } from 'ngxtension/assert-injector';\nimport { Subject, isObservable, of, mergeAll, concatAll, exhaustAll, switchAll } from 'rxjs';\nfunction derivedAsync(computation, options = {}) {\n return assertInjector(derivedAsync, options?.injector, () => {\n const destroyRef = inject(DestroyRef);\n // source$ is a Subject that will emit the new source value\n const sourceEvent$ = new Subject();\n // enhance the sourceEvent$ with the behavior\n const source$ = createFlattenObservable(sourceEvent$, options?.behavior ?? 'switch');\n const sourceResult = source$.subscribe({\n next: value => sourceValue.set({\n kind: 1 /* StateKind.Value */,\n value\n }),\n // NOTE: Error should be handled by the user (using catchError or .catch())\n error: error => sourceValue.set({\n kind: 2 /* StateKind.Error */,\n error\n })\n });\n // we need to unsubscribe the sourceResult when the context gets destroyed\n destroyRef.onDestroy(() => sourceResult.unsubscribe());\n // sourceValue is a signal that will hold the current value and the state of the value\n let sourceValue;\n if (options?.requireSync && options?.initialValue === undefined) {\n const initialCmp = computation(undefined);\n // we don't support promises with requireSync and no initialValue also the typings don't allow this case\n if (isPromise(initialCmp)) {\n throw new Error(REQUIRE_SYNC_PROMISE_MESSAGE);\n }\n sourceValue = signal({\n kind: 0 /* StateKind.NoValue */\n });\n if (isObservable(initialCmp)) {\n sourceEvent$.next(initialCmp);\n } else {\n sourceValue.set({\n kind: 1 /* StateKind.Value */,\n value: initialCmp\n });\n }\n } else {\n sourceValue = signal({\n kind: 1 /* StateKind.Value */,\n value: options?.initialValue\n });\n }\n if (options?.requireSync && sourceValue().kind === 0 /* StateKind.NoValue */) {\n throw new Error(REQUIRE_SYNC_ERROR_MESSAGE);\n }\n let skipFirstComputation = options?.requireSync === true;\n // effect runs inside injection context, so it will be cleanup up when context gets destroyed\n effect(() => {\n // we need to have an untracked() here because we don't want to register the sourceValue as a dependency\n // otherwise, we would have an infinite loop.\n // this is needed for previousValue feature to work\n const currentValue = untracked(() => {\n const currentSourceValue = sourceValue();\n return currentSourceValue.kind === 1 /* StateKind.Value */ ? currentSourceValue.value : undefined;\n });\n const newSource = computation(currentValue);\n // we need to skip the first computation if requireSync is true\n // because we already computed the value in the previous step\n if (skipFirstComputation) {\n skipFirstComputation = false;\n return;\n }\n // we untrack the source$.next() so that we don't register other signals as dependencies\n untracked(() => {\n sourceEvent$.next(isObservable(newSource) || isPromise(newSource) ? newSource : of(newSource));\n });\n });\n // we return a computed value that will return the current value\n // in order to support the same API as computed()\n return computed(() => {\n const state = sourceValue();\n switch (state.kind) {\n case 1 /* StateKind.Value */:\n return state.value;\n case 2 /* StateKind.Error */:\n throw state.error;\n case 0 /* StateKind.NoValue */:\n // we already throw an error if requireSync is true and there is no initialValue,\n // so we don't need to throw an error here\n return;\n default:\n // we should never reach this case\n throw new Error('Unknown state');\n }\n }, {\n equal: options?.equal\n });\n });\n}\nconst REQUIRE_SYNC_PROMISE_MESSAGE = `Promises cannot be used with requireSync. Pass an initialValue or set requireSync to false.`;\nconst REQUIRE_SYNC_ERROR_MESSAGE = `The observable passed to derivedAsync() did not emit synchronously. Pass an initialValue or set requireSync to false.`;\nfunction createFlattenObservable(source, behavior) {\n const KEY_OPERATOR_MAP = {\n merge: mergeAll,\n concat: concatAll,\n exhaust: exhaustAll,\n switch: switchAll\n };\n return source.pipe(KEY_OPERATOR_MAP[behavior]());\n}\nfunction isPromise(value) {\n return value && typeof value.then === 'function';\n}\n\n/**\n * Generated bundle index. Do not edit.\n */\n\nexport { derivedAsync };\n"],"mappings":"2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AG1C,GAAIF,EAAsB,CACxBA,EAAuB,GACvB,MACF,CAEAG,EAAU,IAAM,CACdhB,EAAa,KAAKW,EAAaO,CAAS,GAAKV,EAAUU,CAAS,EAAIA,EAAYC,EAAGD,CAAS,CAAC,CAC/F,CAAC,CACH,CAAC,EAGME,EAAS,IAAM,CACpB,IAAMC,EAAQhB,EAAY,EAC1B,OAAQgB,EAAM,KAAM,CAClB,IAAK,GACH,OAAOA,EAAM,MACf,IAAK,GACH,MAAMA,EAAM,MACd,IAAK,GAGH,OACF,QAEE,MAAM,IAAI,MAAM,eAAe,CACnC,CACF,EAAG,CACD,MAAO1B,GAAS,KAClB,CAAC,CACH,CAAC,CACH,CACA,IAAMc,EAA+B,8FAC/BG,EAA6B,wHACnC,SAAST,EAAwBmB,EAAQC,EAAU,CACjD,IAAMC,EAAmB,CACvB,MAAOC,EACP,OAAQC,EACR,QAASC,EACT,OAAQC,CACV,EACA,OAAON,EAAO,KAAKE,EAAiBD,CAAQ,EAAE,CAAC,CACjD,CACA,SAASf,EAAUJ,EAAO,CACxB,OAAOA,GAAS,OAAOA,EAAM,MAAS,UACxC","names":["assertInjector","fn","injector","runner","assertInInjectionContext","assertedInjector","inject","Injector","runInInjectionContext","derivedAsync","computation","options","assertInjector","destroyRef","inject","DestroyRef","sourceEvent$","Subject","sourceResult","createFlattenObservable","value","sourceValue","error","initialCmp","isPromise","REQUIRE_SYNC_PROMISE_MESSAGE","signal","isObservable","REQUIRE_SYNC_ERROR_MESSAGE","skipFirstComputation","effect","currentValue","untracked","currentSourceValue","newSource","of","computed","state","source","behavior","KEY_OPERATOR_MAP","mergeAll","concatAll","exhaustAll","switchAll"],"x_google_ignoreList":[0,1]}