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

react-listen-resize

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-listen-resize - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

30

dist/index.esm.js
import React, { useState, useReducer, useCallback, useEffect } from 'react';
import throttle from 'lodash/throttle';
import PropTypes from 'prop-types';

@@ -219,2 +218,30 @@

var throttle = function throttle(fn) {
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
var atleast = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 250;
var timer = null;
var previous = null;
return function () {
var context = this;
var args = arguments;
var now = +new Date();
if (!previous) previous = now;
if (now - previous > atleast) {
clearTimeout(timer);
console.log('操作1');
fn.apply(context, args);
console.log('操作3'); // 重置上一次开始时间为本次结束时间
previous = now;
} else {
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
previous = null;
}, delay);
}
};
};
var initialState = {

@@ -298,2 +325,3 @@ innerHeight: window.innerHeight,

innerWidth = event && event.srcElement && event.srcElement.innerWidth || window.innerWidth;
console.log('操作2');
callback && callback({

@@ -300,0 +328,0 @@ eventResize: event,

@@ -9,3 +9,2 @@ 'use strict';

var React__default = _interopDefault(React);
var throttle = _interopDefault(require('lodash/throttle'));
var PropTypes = _interopDefault(require('prop-types'));

@@ -227,2 +226,30 @@

var throttle = function throttle(fn) {
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
var atleast = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 250;
var timer = null;
var previous = null;
return function () {
var context = this;
var args = arguments;
var now = +new Date();
if (!previous) previous = now;
if (now - previous > atleast) {
clearTimeout(timer);
console.log('操作1');
fn.apply(context, args);
console.log('操作3'); // 重置上一次开始时间为本次结束时间
previous = now;
} else {
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
previous = null;
}, delay);
}
};
};
var initialState = {

@@ -306,2 +333,3 @@ innerHeight: window.innerHeight,

innerWidth = event && event.srcElement && event.srcElement.innerWidth || window.innerWidth;
console.log('操作2');
callback && callback({

@@ -308,0 +336,0 @@ eventResize: event,

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('lodash/throttle'), require('prop-types')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', 'lodash/throttle', 'prop-types'], factory) :
(global = global || self, factory(global.ReactListenResize = {}, global.React, global.throttle, global.PropTypes));
}(this, (function (exports, React, throttle, PropTypes) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('prop-types')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', 'prop-types'], factory) :
(global = global || self, factory(global.ReactListenResize = {}, global.React, global.PropTypes));
}(this, (function (exports, React, PropTypes) { 'use strict';
var React__default = 'default' in React ? React['default'] : React;
throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle;
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;

@@ -225,2 +224,30 @@

var throttle = function throttle(fn) {
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
var atleast = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 250;
var timer = null;
var previous = null;
return function () {
var context = this;
var args = arguments;
var now = +new Date();
if (!previous) previous = now;
if (now - previous > atleast) {
clearTimeout(timer);
console.log('操作1');
fn.apply(context, args);
console.log('操作3'); // 重置上一次开始时间为本次结束时间
previous = now;
} else {
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
previous = null;
}, delay);
}
};
};
var initialState = {

@@ -304,2 +331,3 @@ innerHeight: window.innerHeight,

innerWidth = event && event.srcElement && event.srcElement.innerWidth || window.innerWidth;
console.log('操作2');
callback && callback({

@@ -306,0 +334,0 @@ eventResize: event,

2

dist/index.umd.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("lodash/throttle"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","lodash/throttle","prop-types"],t):t((e=e||self).ReactListenResize={},e.React,e.throttle,e.PropTypes)}(this,(function(e,t,r,n){"use strict";var o="default"in t?t.default:t;function i(e,t){for(var r=0;t.length>r;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(){return(a=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function f(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(Object(r),!0).forEach((function(t){c(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function p(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;i.length>n;n++)0>t.indexOf(r=i[n])&&(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;i.length>n;n++)0>t.indexOf(r=i[n])&&Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function y(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var r=[],n=!0,o=!1,i=void 0;try{for(var c,a=e[Symbol.iterator]();!(n=(c=a.next()).done)&&(r.push(c.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r=r&&r.hasOwnProperty("default")?r.default:r,n=n&&n.hasOwnProperty("default")?n.default:n;var m={innerHeight:window.innerHeight,innerWidth:window.innerWidth},h=function(e,t){var r=t&&t.payload||{};switch(t.type){case"update":return f({},e,{},r);default:throw Error()}};function b(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function w(e,t){return e(t={exports:{}},t.exports),t.exports}var v=w((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&Symbol.for,n=r?Symbol.for("react.element"):60103,o=r?Symbol.for("react.portal"):60106,i=r?Symbol.for("react.fragment"):60107,c=r?Symbol.for("react.strict_mode"):60108,a=r?Symbol.for("react.profiler"):60114,u=r?Symbol.for("react.provider"):60109,f=r?Symbol.for("react.context"):60110,s=r?Symbol.for("react.async_mode"):60111,l=r?Symbol.for("react.concurrent_mode"):60111,p=r?Symbol.for("react.forward_ref"):60112,y=r?Symbol.for("react.suspense"):60113,d=r?Symbol.for("react.suspense_list"):60120,m=r?Symbol.for("react.memo"):60115,h=r?Symbol.for("react.lazy"):60116,b=r?Symbol.for("react.fundamental"):60117,w=r?Symbol.for("react.responder"):60118,v=r?Symbol.for("react.scope"):60119;function g(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case n:switch(e=e.type){case s:case l:case i:case a:case c:case y:return e;default:switch(e=e&&e.$$typeof){case f:case p:case h:case m:case u:return e;default:return t}}case o:return t}}}function O(e){return g(e)===l}t.typeOf=g,t.AsyncMode=s,t.ConcurrentMode=l,t.ContextConsumer=f,t.ContextProvider=u,t.Element=n,t.ForwardRef=p,t.Fragment=i,t.Lazy=h,t.Memo=m,t.Portal=o,t.Profiler=a,t.StrictMode=c,t.Suspense=y,t.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===i||e===l||e===a||e===c||e===y||e===d||"object"==typeof e&&null!==e&&(e.$$typeof===h||e.$$typeof===m||e.$$typeof===u||e.$$typeof===f||e.$$typeof===p||e.$$typeof===b||e.$$typeof===w||e.$$typeof===v)},t.isAsyncMode=function(e){return O(e)||g(e)===s},t.isConcurrentMode=O,t.isContextConsumer=function(e){return g(e)===f},t.isContextProvider=function(e){return g(e)===u},t.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===n},t.isForwardRef=function(e){return g(e)===p},t.isFragment=function(e){return g(e)===i},t.isLazy=function(e){return g(e)===h},t.isMemo=function(e){return g(e)===m},t.isPortal=function(e){return g(e)===o},t.isProfiler=function(e){return g(e)===a},t.isStrictMode=function(e){return g(e)===c},t.isSuspense=function(e){return g(e)===y}}));b(v);var g=w((function(e,t){}));b(g);var O=w((function(e){e.exports=v})),j={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},P={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},S={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},E={};function $(e){return O.isMemo(e)?S:E[e.$$typeof]||j}E[O.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0};var R=Object.defineProperty,_=Object.getOwnPropertyNames,x=Object.getOwnPropertySymbols,H=Object.getOwnPropertyDescriptor,W=Object.getPrototypeOf,z=Object.prototype;var C=function e(t,r,n){if("string"!=typeof r){if(z){var o=W(r);o&&o!==z&&e(t,o,n)}var i=_(r);x&&(i=i.concat(x(r)));for(var c=$(t),a=$(r),u=0;i.length>u;++u){var f=i[u];if(!(P[f]||n&&n[f]||a&&a[f]||c&&c[f])){var s=H(r,f);try{R(t,f,s)}catch(e){}}}}return t};function L(e){var t=e.forwardRef,c=void 0!==t&&t;return function(e){var t=function(t){function n(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),(t=y(this,s(n).call(this,e)))._screenResizeHandler=function(e){var r=e&&e.srcElement&&e.srcElement.innerHeight||window.innerHeight,n=e&&e.srcElement&&e.srcElement.innerWidth||window.innerWidth;t.setState({innerHeight:r,innerWidth:n})},t.state={innerHeight:window.innerHeight,innerWidth:window.innerWidth},t.handler=r(t._screenResizeHandler,250),t}var a,u,d;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&l(e,t)}(n,t),a=n,(u=[{key:"componentDidMount",value:function(){window.addEventListener("resize",this.handler)}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.handler)}},{key:"render",value:function(){var t=this.state,r=this.props,n=r.wrappedComponentRef,i=f({innerHeight:t.innerHeight,innerWidth:t.innerWidth},p(r,["wrappedComponentRef"]));return c&&(i.ref=n),o.createElement(e,i)}}])&&i(a.prototype,u),d&&i(a,d),n}(o.Component);if(t.propTypes={wrappedComponentRef:n.oneOfType([n.string,n.func,n.object])},c){var u=o.forwardRef((function(e,r){return o.createElement(t,a({},e,{wrappedComponentRef:r}))}));return u.displayName="ForwardRef(withListenResize(".concat(M(e),"))"),C(u,e)}return t.displayName="withListenResize(".concat(M(e),")"),C(t,e)}}function M(e){return e.displayName||e.name||"Component"}e.createListenResize=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=window.innerHeight,o=window.innerWidth,i=function(t){n=t&&t.srcElement&&t.srcElement.innerHeight||window.innerHeight,o=t&&t.srcElement&&t.srcElement.innerWidth||window.innerWidth,e&&e({eventResize:t,state:{innerHeight:n,innerWidth:o}})},c=r(i,250);return t&&i(),window.addEventListener("resize",c),[{innerHeight:n,innerWidth:o},function(){window.removeEventListener("resize",c)}]},e.createWithListenResize=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return L(f({},e))},e.useListenResize=function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],o=d(t.useState(!1),2),i=o[0],c=o[1],a=d(t.useReducer(h,m),2),u=a[0],f=a[1],s=t.useCallback((function(t){var r=t&&t.srcElement&&t.srcElement.innerHeight||window.innerHeight,n=t&&t.srcElement&&t.srcElement.innerWidth||window.innerWidth;f({type:"update",payload:{innerHeight:r,innerWidth:n}}),e&&e({eventResize:t,state:{innerHeight:r,innerWidth:n}})}),[e]);t.useEffect((function(){c(n)}),[n]),t.useEffect((function(){i&&(s(),c(!1))}),[s,i]);var l=t.useCallback(r(s,250),[]),p=t.useCallback((function(){window.removeEventListener("resize",l)}),[l]);return t.useEffect((function(){return window.addEventListener("resize",l),p}),[p,l]),[u,p]},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t((e=e||self).ReactListenResize={},e.React,e.PropTypes)}(this,(function(e,t,n){"use strict";var r="default"in t?t.default:t;function o(e,t){for(var n=0;t.length>n;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(){return(c=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function u(e){for(var t=1;arguments.length>t;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(e){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;i.length>r;r++)0>t.indexOf(n=i[r])&&(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;i.length>r;r++)0>t.indexOf(n=i[r])&&Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function p(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function y(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var c,a=e[Symbol.iterator]();!(r=(c=a.next()).done)&&(n.push(c.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}n=n&&n.hasOwnProperty("default")?n.default:n;var d=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:250,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:250,r=null,o=null;return function(){var i=this,c=arguments,a=+new Date;o||(o=a),a-o>n?(clearTimeout(r),console.log("操作1"),e.apply(i,c),console.log("操作3"),o=a):(clearTimeout(r),r=setTimeout((function(){e.apply(i,c),o=null}),t))}},m={innerHeight:window.innerHeight,innerWidth:window.innerWidth},h=function(e,t){var n=t&&t.payload||{};switch(t.type){case"update":return u({},e,{},n);default:throw Error()}};function b(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function w(e,t){return e(t={exports:{}},t.exports),t.exports}var v=w((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var n="function"==typeof Symbol&&Symbol.for,r=n?Symbol.for("react.element"):60103,o=n?Symbol.for("react.portal"):60106,i=n?Symbol.for("react.fragment"):60107,c=n?Symbol.for("react.strict_mode"):60108,a=n?Symbol.for("react.profiler"):60114,u=n?Symbol.for("react.provider"):60109,f=n?Symbol.for("react.context"):60110,s=n?Symbol.for("react.async_mode"):60111,l=n?Symbol.for("react.concurrent_mode"):60111,p=n?Symbol.for("react.forward_ref"):60112,y=n?Symbol.for("react.suspense"):60113,d=n?Symbol.for("react.suspense_list"):60120,m=n?Symbol.for("react.memo"):60115,h=n?Symbol.for("react.lazy"):60116,b=n?Symbol.for("react.fundamental"):60117,w=n?Symbol.for("react.responder"):60118,v=n?Symbol.for("react.scope"):60119;function g(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case r:switch(e=e.type){case s:case l:case i:case a:case c:case y:return e;default:switch(e=e&&e.$$typeof){case f:case p:case h:case m:case u:return e;default:return t}}case o:return t}}}function O(e){return g(e)===l}t.typeOf=g,t.AsyncMode=s,t.ConcurrentMode=l,t.ContextConsumer=f,t.ContextProvider=u,t.Element=r,t.ForwardRef=p,t.Fragment=i,t.Lazy=h,t.Memo=m,t.Portal=o,t.Profiler=a,t.StrictMode=c,t.Suspense=y,t.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===i||e===l||e===a||e===c||e===y||e===d||"object"==typeof e&&null!==e&&(e.$$typeof===h||e.$$typeof===m||e.$$typeof===u||e.$$typeof===f||e.$$typeof===p||e.$$typeof===b||e.$$typeof===w||e.$$typeof===v)},t.isAsyncMode=function(e){return O(e)||g(e)===s},t.isConcurrentMode=O,t.isContextConsumer=function(e){return g(e)===f},t.isContextProvider=function(e){return g(e)===u},t.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===r},t.isForwardRef=function(e){return g(e)===p},t.isFragment=function(e){return g(e)===i},t.isLazy=function(e){return g(e)===h},t.isMemo=function(e){return g(e)===m},t.isPortal=function(e){return g(e)===o},t.isProfiler=function(e){return g(e)===a},t.isStrictMode=function(e){return g(e)===c},t.isSuspense=function(e){return g(e)===y}}));b(v);var g=w((function(e,t){}));b(g);var O=w((function(e){e.exports=v})),j={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},P={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},S={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},E={};function $(e){return O.isMemo(e)?S:E[e.$$typeof]||j}E[O.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0};var R=Object.defineProperty,_=Object.getOwnPropertyNames,x=Object.getOwnPropertySymbols,H=Object.getOwnPropertyDescriptor,W=Object.getPrototypeOf,z=Object.prototype;var C=function e(t,n,r){if("string"!=typeof n){if(z){var o=W(n);o&&o!==z&&e(t,o,r)}var i=_(n);x&&(i=i.concat(x(n)));for(var c=$(t),a=$(n),u=0;i.length>u;++u){var f=i[u];if(!(P[f]||r&&r[f]||a&&a[f]||c&&c[f])){var s=H(n,f);try{R(t,f,s)}catch(e){}}}}return t};function T(e){var t=e.forwardRef,i=void 0!==t&&t;return function(e){var t=function(t){function n(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),(t=p(this,f(n).call(this,e)))._screenResizeHandler=function(e){var n=e&&e.srcElement&&e.srcElement.innerHeight||window.innerHeight,r=e&&e.srcElement&&e.srcElement.innerWidth||window.innerWidth;t.setState({innerHeight:n,innerWidth:r})},t.state={innerHeight:window.innerHeight,innerWidth:window.innerWidth},t.handler=d(t._screenResizeHandler,250),t}var c,a,y;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}(n,t),c=n,(a=[{key:"componentDidMount",value:function(){window.addEventListener("resize",this.handler)}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.handler)}},{key:"render",value:function(){var t=this.state,n=this.props,o=n.wrappedComponentRef,c=u({innerHeight:t.innerHeight,innerWidth:t.innerWidth},l(n,["wrappedComponentRef"]));return i&&(c.ref=o),r.createElement(e,c)}}])&&o(c.prototype,a),y&&o(c,y),n}(r.Component);if(t.propTypes={wrappedComponentRef:n.oneOfType([n.string,n.func,n.object])},i){var a=r.forwardRef((function(e,n){return r.createElement(t,c({},e,{wrappedComponentRef:n}))}));return a.displayName="ForwardRef(withListenResize(".concat(L(e),"))"),C(a,e)}return t.displayName="withListenResize(".concat(L(e),")"),C(t,e)}}function L(e){return e.displayName||e.name||"Component"}e.createListenResize=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=window.innerHeight,r=window.innerWidth,o=function(t){n=t&&t.srcElement&&t.srcElement.innerHeight||window.innerHeight,r=t&&t.srcElement&&t.srcElement.innerWidth||window.innerWidth,console.log("操作2"),e&&e({eventResize:t,state:{innerHeight:n,innerWidth:r}})},i=d(o,250);return t&&o(),window.addEventListener("resize",i),[{innerHeight:n,innerWidth:r},function(){window.removeEventListener("resize",i)}]},e.createWithListenResize=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return T(u({},e))},e.useListenResize=function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=y(t.useState(!1),2),o=r[0],i=r[1],c=y(t.useReducer(h,m),2),a=c[0],u=c[1],f=t.useCallback((function(t){var n=t&&t.srcElement&&t.srcElement.innerHeight||window.innerHeight,r=t&&t.srcElement&&t.srcElement.innerWidth||window.innerWidth;u({type:"update",payload:{innerHeight:n,innerWidth:r}}),e&&e({eventResize:t,state:{innerHeight:n,innerWidth:r}})}),[e]);t.useEffect((function(){i(n)}),[n]),t.useEffect((function(){o&&(f(),i(!1))}),[f,o]);var s=t.useCallback(d(f,250),[]),l=t.useCallback((function(){window.removeEventListener("resize",s)}),[s]);return t.useEffect((function(){return window.addEventListener("resize",s),l}),[l,s]),[a,l]},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "react-listen-resize",
"version": "0.1.2",
"version": "0.1.3",
"description": "Listening resize can use hooks、HOC、normal function.",

@@ -77,3 +77,2 @@ "main": "dist/index.js",

"peerDependencies": {
"lodash": ">=4.0.0",
"prop-types": ">=15.7.0",

@@ -83,3 +82,2 @@ "react": ">=16.8.0"

"dependencies": {
"lodash": "^4.17.15",
"prop-types": "^15.7.2",

@@ -86,0 +84,0 @@ "react": "^16.10.2"

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