Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-event-listener

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-event-listener - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

coverage/coverage.json

34

lib/index.js

@@ -90,2 +90,4 @@ 'use strict';

value: function addListeners() {
var _this2 = this;
var _props = this.props;

@@ -97,5 +99,13 @@ var capture = _props.capture;

if (target) {
forEachListener(this.props, function (eventName, listener) {
return on(target, eventName, listener, capture);
});
(function () {
var element = target;
if (typeof target === 'string') {
element = window[target];
}
forEachListener(_this2.props, function (eventName, listener) {
return on(element, eventName, listener, capture);
});
})();
}

@@ -106,2 +116,4 @@ }

value: function removeListeners() {
var _this3 = this;
var _props2 = this.props;

@@ -113,5 +125,13 @@ var capture = _props2.capture;

if (target) {
forEachListener(this.props, function (eventName, listener) {
return off(target, eventName, listener, capture);
});
(function () {
var element = target;
if (typeof target === 'string') {
element = window[target];
}
forEachListener(_this3.props, function (eventName, listener) {
return off(element, eventName, listener, capture);
});
})();
}

@@ -141,3 +161,3 @@ }

*/
target: _react.PropTypes.instanceOf(Node)
target: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.object, _react2.default.PropTypes.string])
};

@@ -144,0 +164,0 @@ EventListener.defaultProps = {

@@ -67,2 +67,20 @@ 'use strict';

describe('props: target', function () {
it('should work with a string', function () {
var handleClick = (0, _sinon.spy)();
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: 'document', onClick: handleClick }), node);
document.body.click();
_chai.assert.strictEqual(handleClick.callCount, 1);
});
it('should work with a node', function () {
var handleClick = (0, _sinon.spy)();
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document, onClick: handleClick }), node);
document.body.click();
_chai.assert.strictEqual(handleClick.callCount, 1);
});
});
[{

@@ -116,3 +134,3 @@ contextName: 'using Simulate.click(extraNode)',

value: function render() {
return _react2.default.createElement(_index2.default, { target: document.body, onClick: this.handleClick });
return _react2.default.createElement(_index2.default, { target: document, onClick: this.handleClick });
}

@@ -146,8 +164,2 @@ }]);

describe('with no node', function () {
it("doesn't throw error", function () {
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { onClick: function onClick() {} }), node);
});
});
describe('when props change', function () {

@@ -157,4 +169,4 @@ it('removes old listeners', function () {

(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document.body, onClick: handleClick }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document.body }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document, onClick: handleClick }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document }), node);

@@ -168,3 +180,3 @@ document.body.click();

(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document.body }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document }), node);

@@ -174,3 +186,3 @@ document.body.click();

(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document.body, onClick: handleClick }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document, onClick: handleClick }), node);

@@ -184,3 +196,3 @@ document.body.click();

(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document.body, onClick: handleClick }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document, onClick: handleClick }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { onClick: handleClick }), node);

@@ -196,3 +208,3 @@

(0, _reactDom.render)(_react2.default.createElement(_index2.default, { onClick: handleClick }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document.body, onClick: handleClick }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document, onClick: handleClick }), node);
document.body.click();

@@ -204,3 +216,3 @@ _chai.assert.strictEqual(handleClick.callCount, 1);

var handleClick = (0, _sinon.spy)();
var inst = (0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document.body, onClick: handleClick }), node);
var inst = (0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document, onClick: handleClick }), node);
var _componentWillUpdate = inst.componentWillUpdate;

@@ -212,3 +224,3 @@ var updated = false;

};
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document.body, onClick: handleClick }), node);
(0, _reactDom.render)(_react2.default.createElement(_index2.default, { target: document, onClick: handleClick }), node);
_chai.assert.strictEqual(updated, false);

@@ -215,0 +227,0 @@ });

{
"name": "react-event-listener",
"version": "0.2.0",
"version": "0.2.1",
"description": "A React component that allow to bind events on the global scope",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -55,3 +55,3 @@ # React event listener

See our [test cases](https://github.com/oliviertassinari/react-event-listener/blob/master/src/__tests__/index.spec.js) for more information.
See our [test cases](https://github.com/oliviertassinari/react-event-listener/blob/master/src/index.spec.js) for more information.

@@ -58,0 +58,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc