rimmel
Version:
A Streams-Oriented UI library for the Rx.Observable Universe
39 lines (36 loc) • 1.97 kB
JavaScript
import { map } from 'rxjs';
import { curry } from '../utils/curry.js';
/**
* An Event Adapter Operator emitting any dataset value from the underlying element instead of a regular DOM Event object
* @category Event Adapter Operators
* @returns OperatorFunction<Event, string>
* @example <button data-foo="bar" onclick="${source(dataset('foo'), stream)}"> ... </button>
**/
const dataset = (key) => map((e) => (e.target.dataset[key]));
/**
* An Event Source emitting any dataset value from the underlying element instead of a regular DOM Event object
* @category Event Adapter Functions
* @param key The key of the dataset item to retrieve
* @param source A handler function or Observer to feed events into
* @returns EventSource<string>
* @example <button data-foo="bar" onclick="${Dataset('foo', stream)}"> ... </button>
* @example <button data-foo="bar" onclick="${Dataset('foo', handlerFn)}"> ... </button>
**/
const Dataset = (key, source) => curry(dataset(key), source);
/**
* An Event Source Operator emitting the full dataset object from the underlying element instead of a regular DOM Event object
* @returns OperatorFunction<Event, DOMStringMap>
* @example <button data-foo="bar" data-baz="bat" onclick="${source(datasetObject, stream)}"> ... </button>
**/
const datasetObject = map((e) => (e.target.dataset));
/**
* An Event Source emitting the full dataset object from the underlying element instead of a regular DOM Event object
* @category Event Adapter Functions
* @param source A handler function or Observer to feed events into
* @returns EventSource<string>
* @example <button data-foo="bar" data-baz="bat" onclick="${DatasetObject(stream)}"> ... </button>
* @example <button data-foo="bar" data-baz="bat" onclick="${DatasetObject(handlerFn)}"> ... </button>
**/
const DatasetObject = (source) => curry(datasetObject, source);
export { Dataset, DatasetObject, dataset, datasetObject };
//# sourceMappingURL=dataset-source.js.map