Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
get(this, 'viewportListeners').forEach((listener) => {
let { context, event } = listener;
context = get(this, 'scrollableArea') || context;
let elem = findElem(context);
let { evtListener } = this._evtListenerClosures.find((closure) => event === closure.event) || {};
elem.removeEventListener(event, evtListener, false);
});
}
_bindListeners(context = null, event = null, element = null) {
assert('You must pass a valid context to _bindListeners', context);
assert('You must pass a valid event to _bindListeners', event);
let elem = findElem(context);
let evtListener = (() => this._debouncedEvent('_setViewportEntered', element));
this._evtListenerClosures.push({ event: event, evtListener });
elem.addEventListener(event, evtListener, false);
},
_bindScrollDirectionListener(sensitivity = 1) {
assert('sensitivity cannot be 0', sensitivity);
const contextEl = get(this, 'scrollableArea') || window;
const elem = findElem(contextEl);
this._debouncedEventHandler = this._debouncedEvent.bind(this, '_triggerDidScrollDirection', elem, sensitivity);
elem.addEventListener('scroll', this._debouncedEventHandler, { passive: true });
},
_unbindScrollDirectionListener() {
const elementId = get(this, 'elementId');
const context = get(this, 'scrollableArea') || window;
const elem = findElem(context);
if (elem) {
elem.removeEventListener('scroll', this._debouncedEventHandler, { passive: true });
delete lastPosition[elementId];
delete lastDirection[elementId];
}
},