10 examples of 'addeventlistener in react' in JavaScript

Every line of 'addeventlistener in react' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
389value: function _attachEventListeners(listeners) {
390 var _this2 = this;
391
392 if (isType(listeners, 'Object')) {
393 Object.keys(listeners).forEach(function (event) {
394 var value = listeners[event];
395 var eventListener,
396 attachMethod = _this2.component_instance.$on; // Parse event listener config
397
398 if (isType(value, 'Function')) {
399 eventListener = value;
400 } else if (isType(value, 'Object')) {
401 var handler = value.handler,
402 _value$once = value.once,
403 once = _value$once === void 0 ? false : _value$once;
404
405 if (once) {
406 attachMethod = _this2.component_instance.$once;
407 }
408
409 eventListener = handler;
410 }
411
412 var callback = function callback() {
413 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
414 args[_key] = arguments[_key];
415 }
416
417 eventListener.apply(_this2, [].concat(args, [_this2.component_instance, _this2]));
418 }; // Attach listener
419
420
421 attachMethod.call(_this2.component_instance, event, callback);
422 });
423 }
424}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

393value: function addEventListener(type, listener) {
394 if (type === 'readystatechange' || type === 'progress') {
395 this._incrementalEvents = true;
396 }
397
398 babelHelpers.get(XMLHttpRequest.prototype.__proto__ || Object.getPrototypeOf(XMLHttpRequest.prototype), "addEventListener", this).call(this, type, listener);
399}
10export function attachEvent(props) {
11
12 props.selection
13 .on('mouseover', _.partialRight(_handleMouseOver, props))
14 .on('mouseout', _.partialRight(_handleMouseOut, props))
15 .on('click', function(d, i, g) {
16 // console.log('clicked!', d, this)
17 props.onClick(d.model);
18 if (props.onClickFinish) {
19 props.onClickFinish(d.model);
20 }
21 });
22}
54componentDidMount: function componentDidMount() {
55 this._isMounted = true;
56 this._fluxible_listeners = [];
57 var self = this;
58
59 // Register static listeners
60 this.getListeners().forEach(function(listener) {
61 self._attachStoreListener(listener);
62 });
63},
77function addEventListener(element, idref) {
78 element.addEventListener('click',
79 function() {
80 chrome.devtools.inspectedWindow.eval(
81 'var element = document.getElementById("' + idref + '");\n' +
82 'if (element) inspect(element);'
83 );
84 });
85}
623addEventListener: function addEventListener() {
624 return null;
625}
41private detachListener(prevProps?: BaseEventProps) {
42 const {event, handler, capture} = prevProps || this.props;
43 removeEventListener(window, event, handler, capture);
44}
7export default function attachEventListener(virtualElement, domElement, eventName, listener, component) {
8 // FF doesn't like it if this isn't a function... this can happen if bad props are passed upstream
9 if (typeof listener === 'function') {
10 let target;
11
12 // If this event is a window-level event, then register it on the window instead of the element
13 // Note that the logic to prevent duplicate subscriptions is supposed to occur upstream of this function!
14 if (Events.window[eventName]) {
15 target = domElement.ownerDocument.defaultView || domElement.ownerDocument.parentWindow;
16 } else {
17 target = domElement;
18 }
19
20 if (target) {
21 if (!component.hasRegisteredListenerOnElement(virtualElement, eventName)) {
22 component.markDidRegisterListenerOnElement(virtualElement, target, eventName, listener);
23 target.addEventListener(eventName, listener);
24 }
25 }
26 }
27}
582addEventListener: function addEventListener(event, handler) {
583 if (!this._eventHandlers[event]) {
584 this._eventHandlers[event] = [];
585 var self = this;
586 this['on' + event] = function (eventObject) {
587 self.dispatchEvent(eventObject);
588 };
589 }
590 this._eventHandlers[event].push(handler);
591},
31addEventListener: function addEventListener(eventName, handler) {
32 _backPressSubscriptions.add(handler);
33
34 return {
35 remove: function remove() {
36 return BackHandler.removeEventListener(eventName, handler);
37 }
38 };
39},

Related snippets