-
Notifications
You must be signed in to change notification settings - Fork 0
Library: pumpEvent()
Eugene Lazutkin edited this page Jul 5, 2018
·
3 revisions
pumpEvent() module is a function, which is used to throttle events using a time-handling function, e.g., delay().
The definition is very simple:
import delay from './delay';
import getPath from './getPath';
const pumpEvent = (target, attrName, path='', ms=500, wrap=delay) =>
wrap(e => {
target.setAttribute(attrName, getPath(e, path));
}, ms);In a module-enabled environment (like Babel) it can be accessed like that:
import pumpEvent from '@researchnow/reno/src/utils/pumpEvent';In global-based environments (like a browser) it is frequently mapped to Reno.utils.pumpEvent.
The function takes the following arguments:
-
targetis a DOM node, which is usually a web component. It will be controlled by events. -
attrNameis an attribute name, which will be set according to events. -
pathis an object path (see getPath()). It is used on an event object to extract a value for the attribute, usually from thedetailpart. -
msis a positive integer, which specifies a time delay to collect events. -
wrapis a time-handling function, which wraps the setting of an attribute. It consumesmsas well.- See debounce(), delay(), throttle() as examples of time-handling functions.
This function returns an event handler function.
The example below updates reno-table according to changes in reno-search.
const renoTable = document.querySelector('reno-table');
document.documentElement.addEventListener('reno-change',
Reno.utils.pumpEvent(renoTable, 'filter', 'detail.value'));