1import { TalkbackFn, TeardownFn, Start, Push, SignalKind } from './types';
2
3/** Placeholder {@link TeardownFn | teardown functions} that's a no-op.
4 * @see {@link TeardownFn} for the definition and usage of teardowns.
5 * @internal
6 */
7export const teardownPlaceholder: TeardownFn = () => {
8 /*noop*/
9};
10
11/** Placeholder {@link TalkbackFn | talkback function} that's a no-op.
12 * @privateRemarks
13 * This is frequently used in the codebase as a no-op initializer value for talkback functions in
14 * the implementation of {@link Operator | Operators}. This is cheaper than initializing the
15 * variables of talkbacks to `undefined` or `null` and performing an extra check before calling
16 * them. Since the {@link Start | Start signal} is assumed to come first and carry a talkback, we can
17 * use this to our advantage and use a no-op placeholder before {@link Start} is received.
18 *
19 * @internal
20 */
21export const talkbackPlaceholder: TalkbackFn = teardownPlaceholder;
22
23/** Wraps the passed {@link TalkbackFn | talkback function} in a {@link Start | Start signal}.
24 * @internal
25 */
26export function start<T>(talkback: TalkbackFn): Start<T> {
27 return {
28 tag: SignalKind.Start,
29 0: talkback,
30 } as Start<T>;
31}
32
33/** Wraps the passed value in a {@link Push | Push signal}.
34 * @internal
35 */
36export function push<T>(value: T): Push<T> {
37 return {
38 tag: SignalKind.Push,
39 0: value,
40 } as Push<T>;
41}