UNPKG

rimmel

Version:

A Streams-Oriented UI library for the Rx.Observable Universe

38 lines (35 loc) 1.43 kB
import { autoValue } from '../utils/auto-value.js'; /** * @deprecated don't use **/ const isObjectSource = (expression) => Array.isArray(expression) && expression.length == 2; /** * A data source that updates an object's property from an &lt;input&gt; element when * a certain event occurs * @param key an ['property', object] or [index, array] pair to update * @returns A data source * @example <input oninput="${[obj, 'property']}"> * @example <input oninput="${ObjectSource('property', obj)}"> * @example <input oninput="${ObjectSource(4, arr)}"> */ const ObjectSource = (key, targetObject) => { const handler = ((targetObject, e) => { const t = e.target; targetObject[key] = autoValue(t); }); return (targetObject ? handler.bind(null, targetObject) : (t2) => handler.bind(null, t2)); }; /** * An Event Adapter that uses an event's underlying &lt;input&gt; element * to updates an object's property or an array item. * @param property A property to update in the given object or an index to update in the given array * @param object The object or array to update * @returns An event handler */ const Update = (property, object) => ObjectSource(property, object); const asObjectSource = ObjectSource; const AsObjectSource = ObjectSource; export { AsObjectSource, ObjectSource, Update, asObjectSource, isObjectSource }; //# sourceMappingURL=object-source.js.map