New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-component-visibility

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-component-visibility - npm Package Compare versions

Comparing version
0.0.7
to
0.0.8
.npmignore

Sorry, the diff of this file is not supported yet

+81
var assert = require('chai').assert;
var jsdom = require('jsdom');
var mixin = require('../');
var React;
before(function () {
React = require('react');
global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.window = document.parentWindow;
});
function fireEvent(type) {
// NOTE: initEvent is deprecated
// TODO: Replace with `new window.Event()` when jsdom supports it
var event = document.createEvent(type);
event.initEvent(type, false, false);
if (type == 'resize') {
window.dispatchEvent(event);
} else {
document.dispatchEvent(event);
}
}
function wait(done) {
// Wait for at least RATE_LIMIT (default 25)
return setTimeout(function () {
done();
}, 30);
}
describe('react-component-visibility', function () {
var component;
var element;
beforeEach(function () {
component = React.createClass({
mixins: [mixin],
render: function () {
return React.createElement('div', {}, 'hello');
}
});
element = React.render(React.createElement(component), document.body);
});
function testEvent(type) {
describe(type, function () {
it('should trigger checkComponentVisibility', function (done) {
element.checkComponentVisibility = function () {
done();
};
fireEvent(type);
})
it('should not trigger checkComponentVisibility if disabled', function (done) {
element.disableVisbilityHandling();
element.checkComponentVisibility = function () {
done(new Error('should not run'));
};
fireEvent(type);
wait(done);
});
it('should not trigger checkComponentVisibility if unmounted', function (done) {
// fire event to trigger rate limit
fireEvent(type);
React.unmountComponentAtNode(document.body);
element.checkComponentVisibility = function () {
done(new Error('should not run'));
};
fireEvent(type);
wait(done);
});
});
}
testEvent('resize');
testEvent('scroll');
testEvent('visibilitychange');
});
+12
-11
(function() {
if (typeof window === "undefined") {
return console.error("This environment lacks 'window' support.");
}
var React = typeof window !== 'undefined' && window.React || require('react');
if (typeof document === "undefined") {
return console.error("This environment lacks 'document' support.");
}
var React = window.React || require('react');
var RATE_LIMIT = 25;

@@ -39,3 +31,3 @@

var domnode = this._dom_node,
gcs = getComputedStyle(domnode, false),
gcs = window.getComputedStyle(domnode, false),
dims = domnode.getBoundingClientRect(),

@@ -89,2 +81,10 @@ h = window.innerHeight,

enableVisbilityHandling: function(checkNow) {
if (typeof window === "undefined") {
return console.error("This environment lacks 'window' support.");
}
if (typeof document === "undefined") {
return console.error("This environment lacks 'document' support.");
}
if (!this._dom_node) {

@@ -102,3 +102,3 @@ this._dom_node = React.findDOMNode(this);

this.checkComponentVisibility();
setTimeout(function() {
this._rcv_timeout = setTimeout(function() {
this._rcv_lock = false;

@@ -132,2 +132,3 @@ if (this._rcv_schedule) {

disableVisbilityHandling: function() {
clearTimeout(this._rcv_timeout);
if (this._rcv_fn) {

@@ -134,0 +135,0 @@ var domnode = this._dom_node;

{
"name": "react-component-visibility",
"version": "0.0.7",
"version": "0.0.8",
"description": "A mixin for determining whether a component is visible to the user or not.",

@@ -21,3 +21,11 @@ "main": "index.js",

},
"scripts": {
"test": "mocha"
},
"homepage": "https://github.com/Pomax/react-component-visibility",
"devDependencies": {
"chai": "^3.2.0",
"jsdom": "^3.1.2",
"react": "^0.13.0"
},
"peerDependencies": {

@@ -24,0 +32,0 @@ "react": "^0.13"