( task: TaskDescriptor | ComputedDescriptor<unknown>, containerState: ContainerState, rCtx: RenderContext )
| 670 | }; |
| 671 | |
| 672 | export const runTask = ( |
| 673 | task: TaskDescriptor | ComputedDescriptor<unknown>, |
| 674 | containerState: ContainerState, |
| 675 | rCtx: RenderContext |
| 676 | ): ValueOrPromise<void> => { |
| 677 | task.$flags$ &= ~TaskFlagsIsDirty; |
| 678 | |
| 679 | cleanupTask(task); |
| 680 | const hostElement = task.$el$; |
| 681 | const iCtx = newInvokeContext(rCtx.$static$.$locale$, hostElement, undefined, TaskEvent); |
| 682 | iCtx.$renderCtx$ = rCtx; |
| 683 | const { $subsManager$: subsManager } = containerState; |
| 684 | const taskFn = task.$qrl$.getFn(iCtx, () => { |
| 685 | subsManager.$clearSub$(task); |
| 686 | }) as TaskFn; |
| 687 | const track: Tracker = (obj: (() => unknown) | object | Signal, prop?: string) => { |
| 688 | if (isFunction(obj)) { |
| 689 | const ctx = newInvokeContext(); |
| 690 | ctx.$subscriber$ = [0, task]; |
| 691 | return invoke(ctx, obj); |
| 692 | } |
| 693 | const manager = getSubscriptionManager(obj); |
| 694 | if (manager) { |
| 695 | manager.$addSub$([0, task], prop); |
| 696 | } else { |
| 697 | logErrorAndStop(codeToText(QError_trackUseStore), obj); |
| 698 | } |
| 699 | if (prop) { |
| 700 | return (obj as Record<string, unknown>)[prop]; |
| 701 | } else if (isSignal(obj)) { |
| 702 | return obj.value; |
| 703 | } else { |
| 704 | return obj; |
| 705 | } |
| 706 | }; |
| 707 | const cleanups: (() => void)[] = []; |
| 708 | task.$destroy$ = noSerialize(() => { |
| 709 | cleanups.forEach((fn) => fn()); |
| 710 | }); |
| 711 | |
| 712 | const opts: TaskCtx = { |
| 713 | track, |
| 714 | cleanup(callback) { |
| 715 | cleanups.push(callback); |
| 716 | }, |
| 717 | }; |
| 718 | return safeCall( |
| 719 | () => taskFn(opts), |
| 720 | (returnValue) => { |
| 721 | if (isFunction(returnValue)) { |
| 722 | cleanups.push(returnValue); |
| 723 | } |
| 724 | }, |
| 725 | (reason) => { |
| 726 | handleError(reason, hostElement, rCtx); |
| 727 | } |
| 728 | ); |
| 729 | }; |
no test coverage detected
searching dependent graphs…