Files
angular/packages/core/test/signals/effect_util.ts
Joey Perrott 31fdf0fbea refactor: migrate core to prettier formatting (#55488)
Migrate formatting to prettier for core from clang-format

PR Close #55488
2024-04-29 09:49:19 -07:00

35 lines
824 B
TypeScript

/**
* @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.io/license
*/
import {createWatch, Watch, WatchCleanupFn} from '@angular/core/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();
}
export function flushEffects(): void {
for (const watch of queue) {
queue.delete(watch);
watch.run();
}
}
export function resetEffects(): void {
queue.clear();
}