rimmel
Version:
A Streams-Oriented UI library for the Rx.Observable Universe
27 lines (24 loc) • 969 B
JavaScript
import { map } from 'rxjs';
import { curry } from '../utils/curry.js';
/**
* An Event Source Operator that "cuts" the value of the underlying <input> element
* and resets it to the provided value or empty otherwise
* @param handler A handler function or observer to send events to
* @returns EventSource<string>
*/
const swap = (replacement) => map((e) => {
const t = e.target;
const v = t.value;
t.value = typeof replacement == 'function' ? replacement(v) : replacement;
return v;
});
/**
* An Event Source that "cuts" the value of the underlying <input> element
* and resets it to the provided value or empty otherwise
* @param replacement A new value to swap the current element's value with
* @param source A handler function or observer to send events to
* @returns EventSource<string>
*/
const Swap = (replacement = '', source) => curry(swap(replacement), source);
export { Swap, swap };
//# sourceMappingURL=swap-source.js.map