mapTo
Maps all emitted values to a constant value, ignoring the source values.
Emits on every source value although the value never changes — where
map(() => value) would stop every result after the first as equal — so it
is the one for turning events into a value. The value’s type is inferred as
written, as with as const: mapTo('reset') gives 'reset', not string.
Marble Diagram
Section titled “Marble Diagram”mapTo(1)
Example
Section titled “Example”// Timeline://// click$ MouseEvent MouseEvent MouseEvent// count$ 1 1 1//// Explanation:// - mapTo maps all emitted values to a constant value// - Ignores the source values entirely// - Useful for converting events to signals
const click$ = source<string>();
const one$ = click$.pipe(mapTo(1));
const valueHistory: number[] = [];
one$.subscribe((value) => { valueHistory.push(value);});
click$.next('click1');
click$.next('click2');
click$.next('click3');
assert.deepStrictEqual(valueHistory, [1, 1, 1]);