{"version":3,"file":"ngxtension-explicit-effect.mjs","sources":["../../../../libs/ngxtension/explicit-effect/src/explicit-effect.ts","../../../../libs/ngxtension/explicit-effect/src/ngxtension-explicit-effect.ts"],"sourcesContent":["import {\n\tCreateEffectOptions,\n\tEffectCleanupRegisterFn,\n\tEffectRef,\n\teffect,\n\tuntracked,\n} from '@angular/core';\n\n/**\n * We want to have the Tuple in order to use the types in the function signature\n */\ntype ExplicitEffectValues<T> = {\n\t[K in keyof T]: () => T[K];\n};\n\n/**\n * Extend the regular set of effect options\n */\ndeclare interface CreateExplicitEffectOptions extends CreateEffectOptions {\n\t/**\n\t * Option that allows the computation not to execute immediately, but only run on first change.\n\t */\n\tdefer?: boolean;\n}\n\n/**\n * This explicit effect function will take the dependencies and the function to run when the dependencies change.\n *\n * @example\n * ```typescript\n * import { explicitEffect } from 'ngxtension/explicit-effect';\n *\n * const count = signal(0);\n * const state = signal('idle');\n *\n * explicitEffect([count, state], ([count, state], cleanup) => {\n *   console.log('count updated', count, state);\n *\n *   cleanup(() => {\n *     console.log('cleanup');\n *   });\n * });\n * ```\n *\n * @param deps - The dependencies that the effect will run on\n * @param fn - The function to run when the dependencies change\n * @param options - The options for the effect with the addition of defer (it allows the computation to run on first change, not immediately)\n */\nexport function explicitEffect<\n\tInput extends readonly unknown[],\n\tParams = Input,\n>(\n\tdeps: readonly [...ExplicitEffectValues<Input>],\n\tfn: (deps: Params, onCleanup: EffectCleanupRegisterFn) => void,\n\toptions?: CreateExplicitEffectOptions | undefined,\n): EffectRef {\n\tlet defer = options && options.defer;\n\treturn effect((onCleanup) => {\n\t\tconst depValues = deps.map((s) => s());\n\t\tuntracked(() => {\n\t\t\tif (!defer) {\n\t\t\t\tfn(depValues as any, onCleanup);\n\t\t\t}\n\t\t\tdefer = false;\n\t\t});\n\t}, options);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAyBA;;;;;;;;;;;;;;;;;;;;;;AAsBG;SACa,cAAc,CAI7B,IAA+C,EAC/C,EAA8D,EAC9D,OAAiD,EAAA;AAEjD,IAAA,IAAI,KAAK,GAAG,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC;AACrC,IAAA,OAAO,MAAM,CAAC,CAAC,SAAS,KAAI;AAC3B,QAAA,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvC,SAAS,CAAC,MAAK;YACd,IAAI,CAAC,KAAK,EAAE;AACX,gBAAA,EAAE,CAAC,SAAgB,EAAE,SAAS,CAAC,CAAC;aAChC;YACD,KAAK,GAAG,KAAK,CAAC;AACf,SAAC,CAAC,CAAC;KACH,EAAE,OAAO,CAAC,CAAC;AACb;;AClEA;;AAEG;;;;"}