/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/core/test/signals/effect_util.ts
39 строк
884 B
Andrew Kushnir
refactor(core): convert scripts within `packages/core/test` to relative imports (#60227)
25 мар 2025, 20:58
25 мар 2025, 20:58
ae047c5
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {createWatch, Watch, WatchCleanupFn} from '../../primitives/signals'; let queue = new Set<Watch>(); /** * A wrapper around `Watch` that emulates the `effect` API and allows for more streamlined testing. */ export function testingEffect( effectFn: (onCleanup: (cleanupFn: WatchCleanupFn) => void) => void, ): () => void { const w = createWatch(effectFn, queue.add.bind(queue), true); // Effects start dirty. w.notify(); return () => { queue.delete(w); w.destroy(); }; } export function flushEffects(): void { for (const watch of queue) { queue.delete(watch); watch.run(); } } export function resetEffects(): void { queue.clear(); }