react-interval
Advanced tools
Comparing version 1.3.3 to 2.0.1
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(require("react")); | ||
module.exports = factory(require("React")); | ||
else if(typeof define === 'function' && define.amd) | ||
define(["react"], factory); | ||
define(["React"], factory); | ||
else if(typeof exports === 'object') | ||
exports["ReactInterval"] = factory(require("react")); | ||
exports["ReactInterval"] = factory(require("React")); | ||
else | ||
@@ -19,10 +19,10 @@ root["ReactInterval"] = factory(root["React"]); | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ exports: {}, | ||
/******/ id: moduleId, | ||
/******/ loaded: false | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
@@ -34,3 +34,3 @@ /******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.loaded = true; | ||
/******/ module.l = true; | ||
/******/ | ||
@@ -48,2 +48,28 @@ /******/ // Return the exports of the module | ||
/******/ | ||
/******/ // identity function for calling harmony imports with the correct context | ||
/******/ __webpack_require__.i = function(value) { return value; }; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { | ||
/******/ configurable: false, | ||
/******/ enumerable: true, | ||
/******/ get: getter | ||
/******/ }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
@@ -53,3 +79,3 @@ /******/ __webpack_require__.p = ""; | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(0); | ||
/******/ return __webpack_require__(__webpack_require__.s = 1); | ||
/******/ }) | ||
@@ -59,99 +85,124 @@ /************************************************************************/ | ||
/* 0 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
var ReactInterval = __webpack_require__(1).ReactInterval; | ||
ReactInterval.ReactInterval = ReactInterval; | ||
module.exports = ReactInterval; | ||
"use strict"; | ||
/***/ }, | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.ReactInterval = undefined; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _react = __webpack_require__(2); | ||
var _react2 = _interopRequireDefault(_react); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var ReactInterval = exports.ReactInterval = function (_React$Component) { | ||
_inherits(ReactInterval, _React$Component); | ||
function ReactInterval() { | ||
var _ref; | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, ReactInterval); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ReactInterval.__proto__ || Object.getPrototypeOf(ReactInterval)).call.apply(_ref, [this].concat(args))), _this), _this.callback = function () { | ||
if (_this.timer) { | ||
_this.props.callback(); | ||
_this.start(); | ||
} | ||
}, _this.start = function () { | ||
_this.stop(); | ||
_this.timer = setTimeout(_this.callback, _this.props.timeout); | ||
}, _this.stop = function () { | ||
clearTimeout(_this.timer); | ||
_this.timer = null; | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
_createClass(ReactInterval, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
if (this.props.enabled) { | ||
this.start(); | ||
} | ||
} | ||
}, { | ||
key: 'shouldComponentUpdate', | ||
value: function shouldComponentUpdate(_ref2) { | ||
var timeout = _ref2.timeout, | ||
callback = _ref2.callback, | ||
enabled = _ref2.enabled; | ||
return this.props.timeout !== timeout || this.props.callback !== callback || this.props.enabled !== enabled; | ||
} | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate(_ref3) { | ||
var enabled = _ref3.enabled; | ||
if (this.props.enabled !== enabled) { | ||
if (this.props.enabled) { | ||
this.start(); | ||
} else { | ||
this.stop(); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this.stop(); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
return false; | ||
} | ||
}]); | ||
return ReactInterval; | ||
}(_react2.default.Component); | ||
ReactInterval.defaultProps = { | ||
enabled: false, | ||
timeout: 1000 | ||
}; | ||
/***/ }), | ||
/* 1 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/***/ (function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.ReactInterval = undefined; | ||
var _react = __webpack_require__(2); | ||
var _react2 = _interopRequireDefault(_react); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var ReactInterval = exports.ReactInterval = _react2.default.createClass({ | ||
displayName: 'ReactInterval', | ||
propTypes: { | ||
callback: _react2.default.PropTypes.func.isRequired, | ||
enabled: _react2.default.PropTypes.bool, | ||
timeout: _react2.default.PropTypes.number | ||
}, | ||
getDefaultProps: function getDefaultProps() { | ||
return { | ||
enabled: false, | ||
timeout: 1000 | ||
}; | ||
}, | ||
componentDidMount: function componentDidMount() { | ||
if (this.props.enabled) { | ||
this.start(); | ||
} | ||
}, | ||
shouldComponentUpdate: function shouldComponentUpdate(_ref) { | ||
var timeout = _ref.timeout; | ||
var callback = _ref.callback; | ||
var enabled = _ref.enabled; | ||
return this.props.timeout !== timeout || this.props.callback !== callback || this.props.enabled !== enabled; | ||
}, | ||
componentDidUpdate: function componentDidUpdate(_ref2) { | ||
var enabled = _ref2.enabled; | ||
if (this.props.enabled !== enabled) { | ||
if (this.props.enabled) { | ||
this.start(); | ||
} else { | ||
this.stop(); | ||
} | ||
} | ||
}, | ||
componentWillUnmount: function componentWillUnmount() { | ||
this.stop(); | ||
}, | ||
callback: function callback() { | ||
if (this.timer) { | ||
this.props.callback(); | ||
this.start(); | ||
} | ||
}, | ||
start: function start() { | ||
this.stop(); | ||
this.timer = setTimeout(this.callback, this.props.timeout); | ||
}, | ||
stop: function stop() { | ||
clearTimeout(this.timer); | ||
this.timer = null; | ||
}, | ||
render: function render() { | ||
return false; | ||
} | ||
}); | ||
"use strict"; | ||
/***/ }, | ||
var _require = __webpack_require__(0), | ||
ReactInterval = _require.ReactInterval; | ||
ReactInterval.ReactInterval = ReactInterval; | ||
module.exports = ReactInterval; | ||
/***/ }), | ||
/* 2 */ | ||
/***/ function(module, exports) { | ||
/***/ (function(module, exports) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_2__; | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_2__; | ||
/***/ } | ||
/******/ ]) | ||
}); | ||
; | ||
//# sourceMappingURL=react-interval.js.map | ||
/***/ }) | ||
/******/ ]); | ||
}); |
@@ -1,2 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ReactInterval=e(require("react")):t.ReactInterval=e(t.React)}(this,function(t){return function(t){function e(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var o={};return e.m=t,e.c=o,e.p="",e(0)}([function(t,e,o){"use strict";var n=o(1).ReactInterval;n.ReactInterval=n,t.exports=n},function(t,e,o){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}Object.defineProperty(e,"__esModule",{value:!0}),e.ReactInterval=void 0;var r=o(2),a=n(r);e.ReactInterval=a["default"].createClass({displayName:"ReactInterval",propTypes:{callback:a["default"].PropTypes.func.isRequired,enabled:a["default"].PropTypes.bool,timeout:a["default"].PropTypes.number},getDefaultProps:function(){return{enabled:!1,timeout:1e3}},componentDidMount:function(){this.props.enabled&&this.start()},shouldComponentUpdate:function(t){var e=t.timeout,o=t.callback,n=t.enabled;return this.props.timeout!==e||this.props.callback!==o||this.props.enabled!==n},componentDidUpdate:function(t){var e=t.enabled;this.props.enabled!==e&&(this.props.enabled?this.start():this.stop())},componentWillUnmount:function(){this.stop()},callback:function(){this.timer&&(this.props.callback(),this.start())},start:function(){this.stop(),this.timer=setTimeout(this.callback,this.props.timeout)},stop:function(){clearTimeout(this.timer),this.timer=null},render:function(){return!1}})},function(e,o){e.exports=t}])}); | ||
//# sourceMappingURL=react-interval.min.js.map | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("React")):"function"==typeof define&&define.amd?define(["React"],t):"object"==typeof exports?exports.ReactInterval=t(require("React")):e.ReactInterval=t(e.React)}(this,function(e){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0}),t.ReactInterval=void 0;var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),i=n(2),c=function(e){return e&&e.__esModule?e:{default:e}}(i);(t.ReactInterval=function(e){function t(){var e,n,u,a;o(this,t);for(var i=arguments.length,c=Array(i),l=0;l<i;l++)c[l]=arguments[l];return n=u=r(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(c))),u.callback=function(){u.timer&&(u.props.callback(),u.start())},u.start=function(){u.stop(),u.timer=setTimeout(u.callback,u.props.timeout)},u.stop=function(){clearTimeout(u.timer),u.timer=null},a=n,r(u,a)}return u(t,e),a(t,[{key:"componentDidMount",value:function(){this.props.enabled&&this.start()}},{key:"shouldComponentUpdate",value:function(e){var t=e.timeout,n=e.callback,o=e.enabled;return this.props.timeout!==t||this.props.callback!==n||this.props.enabled!==o}},{key:"componentDidUpdate",value:function(e){var t=e.enabled;this.props.enabled!==t&&(this.props.enabled?this.start():this.stop())}},{key:"componentWillUnmount",value:function(){this.stop()}},{key:"render",value:function(){return!1}}]),t}(c.default.Component)).defaultProps={enabled:!1,timeout:1e3}},function(e,t,n){"use strict";var o=n(0),r=o.ReactInterval;r.ReactInterval=r,e.exports=r},function(t,n){t.exports=e}])}); |
@@ -8,2 +8,4 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _react = require('react'); | ||
@@ -15,61 +17,83 @@ | ||
var ReactInterval = exports.ReactInterval = _react2.default.createClass({ | ||
displayName: 'ReactInterval', | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
propTypes: { | ||
callback: _react2.default.PropTypes.func.isRequired, | ||
enabled: _react2.default.PropTypes.bool, | ||
timeout: _react2.default.PropTypes.number | ||
}, | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
getDefaultProps: function getDefaultProps() { | ||
return { | ||
enabled: false, | ||
timeout: 1000 | ||
}; | ||
}, | ||
componentDidMount: function componentDidMount() { | ||
if (this.props.enabled) { | ||
this.start(); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var ReactInterval = exports.ReactInterval = function (_React$Component) { | ||
_inherits(ReactInterval, _React$Component); | ||
function ReactInterval() { | ||
var _ref; | ||
var _temp, _this, _ret; | ||
_classCallCheck(this, ReactInterval); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
}, | ||
shouldComponentUpdate: function shouldComponentUpdate(_ref) { | ||
var timeout = _ref.timeout; | ||
var callback = _ref.callback; | ||
var enabled = _ref.enabled; | ||
return this.props.timeout !== timeout || this.props.callback !== callback || this.props.enabled !== enabled; | ||
}, | ||
componentDidUpdate: function componentDidUpdate(_ref2) { | ||
var enabled = _ref2.enabled; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ReactInterval.__proto__ || Object.getPrototypeOf(ReactInterval)).call.apply(_ref, [this].concat(args))), _this), _this.callback = function () { | ||
if (_this.timer) { | ||
_this.props.callback(); | ||
_this.start(); | ||
} | ||
}, _this.start = function () { | ||
_this.stop(); | ||
_this.timer = setTimeout(_this.callback, _this.props.timeout); | ||
}, _this.stop = function () { | ||
clearTimeout(_this.timer); | ||
_this.timer = null; | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
if (this.props.enabled !== enabled) { | ||
_createClass(ReactInterval, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
if (this.props.enabled) { | ||
this.start(); | ||
} else { | ||
this.stop(); | ||
} | ||
} | ||
}, | ||
componentWillUnmount: function componentWillUnmount() { | ||
this.stop(); | ||
}, | ||
callback: function callback() { | ||
if (this.timer) { | ||
this.props.callback(); | ||
this.start(); | ||
}, { | ||
key: 'shouldComponentUpdate', | ||
value: function shouldComponentUpdate(_ref2) { | ||
var timeout = _ref2.timeout, | ||
callback = _ref2.callback, | ||
enabled = _ref2.enabled; | ||
return this.props.timeout !== timeout || this.props.callback !== callback || this.props.enabled !== enabled; | ||
} | ||
}, | ||
start: function start() { | ||
this.stop(); | ||
this.timer = setTimeout(this.callback, this.props.timeout); | ||
}, | ||
stop: function stop() { | ||
clearTimeout(this.timer); | ||
this.timer = null; | ||
}, | ||
render: function render() { | ||
return false; | ||
} | ||
}); | ||
//# sourceMappingURL=Component.js.map | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate(_ref3) { | ||
var enabled = _ref3.enabled; | ||
if (this.props.enabled !== enabled) { | ||
if (this.props.enabled) { | ||
this.start(); | ||
} else { | ||
this.stop(); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this.stop(); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
return false; | ||
} | ||
}]); | ||
return ReactInterval; | ||
}(_react2.default.Component); | ||
ReactInterval.defaultProps = { | ||
enabled: false, | ||
timeout: 1000 | ||
}; |
@@ -1,8 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
var ReactInterval = require('./Component').ReactInterval; | ||
var _require = require("./Component"), | ||
ReactInterval = _require.ReactInterval; | ||
ReactInterval.ReactInterval = ReactInterval; | ||
module.exports = ReactInterval; | ||
//# sourceMappingURL=index.js.map | ||
module.exports = ReactInterval; |
{ | ||
"name": "react-interval", | ||
"version": "1.3.3", | ||
"version": "2.0.1", | ||
"description": "Safe React wrapper for setInterval", | ||
@@ -10,13 +10,6 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"start": "react-component-template", | ||
"test": "npm start test", | ||
"precommit": "npm start precommit", | ||
"prepush": "npm start prepush", | ||
"postversion": "npm start postversion", | ||
"prepublish": "npm start prepublish" | ||
"start": "../../scripts/start.js", | ||
"prepublish": "npm start -s build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/nkbt/react-interval.git" | ||
}, | ||
"repository": "https://github.com/nkbt/react-works/tree/master/packages/interval", | ||
"keywords": [ | ||
@@ -36,11 +29,20 @@ "component", | ||
"bugs": { | ||
"url": "https://github.com/nkbt/react-interval/issues" | ||
"url": "https://github.com/nkbt/react-works/issues", | ||
"email": "nik@butenko.me" | ||
}, | ||
"homepage": "https://github.com/nkbt/react-interval", | ||
"homepage": "https://github.com/nkbt/react-works/tree/master/packages/interval", | ||
"peerDependencies": { | ||
"react": "^0.14 || ^15" | ||
"react": "^15.3.0" | ||
}, | ||
"devDependencies": { | ||
"react-component-template": "0.1.6" | ||
} | ||
"dependencies": { | ||
"prop-types": "^15.5.10" | ||
}, | ||
"files": [ | ||
"build", | ||
"lib", | ||
"src", | ||
"LICENSE", | ||
"package.json", | ||
"README.md" | ||
] | ||
} |
# react-interval [![npm](https://img.shields.io/npm/v/react-interval.svg?style=flat-square)](https://www.npmjs.com/package/react-interval) | ||
Safe React wrapper for setInterval | ||
[![Gitter](https://img.shields.io/gitter/room/nkbt/help.svg?style=flat-square)](https://gitter.im/nkbt/help) | ||
[![CircleCI](https://img.shields.io/circleci/project/nkbt/react-interval.svg?style=flat-square&label=nix-build)](https://circleci.com/gh/nkbt/react-interval) | ||
[![AppVeyor](https://img.shields.io/appveyor/ci/nkbt/react-interval.svg?style=flat-square&label=win-build)](https://ci.appveyor.com/project/nkbt/react-interval) | ||
[![Coverage](https://img.shields.io/codecov/c/github/nkbt/react-interval.svg?style=flat-square)](https://codecov.io/github/nkbt/react-interval?branch=master) | ||
[![Dependencies](https://img.shields.io/david/nkbt/react-interval.svg?style=flat-square)](https://david-dm.org/nkbt/react-interval) | ||
[![Dev Dependencies](https://img.shields.io/david/dev/nkbt/react-interval.svg?style=flat-square)](https://david-dm.org/nkbt/react-interval#info=devDependencies) | ||
Safe React wrapper for setInterval | ||
## Installation | ||
![React Interval](./src/example/react-interval.gif) | ||
### NPM | ||
## Installation | ||
### NPM | ||
```sh | ||
@@ -27,12 +22,7 @@ npm install --save react react-interval | ||
### Bower: | ||
```sh | ||
bower install --save https://unpkg.com/react-interval/bower.zip | ||
``` | ||
### 1998 Script Tag: | ||
### 1998 Script Tag: | ||
```html | ||
<script src="https://unpkg.com/react/dist/react.js"></script> | ||
<script src="https://unpkg.com/react-interval/build/react-interval.js"></script> | ||
<script src="https://unpkg.com/react/dist/react.min.js"></script> | ||
<script src="https://unpkg.com/react-interval/build/react-interval.min.js"></script> | ||
(Module exposed as `ReactInterval`) | ||
@@ -140,33 +130,4 @@ ``` | ||
## Development and testing | ||
Currently is being developed and tested with the latest stable `Node 6` on `OSX` and `Windows`. | ||
To run example covering all `ReactInterval` features, use `npm start dev`, which will compile `src/example/Example.js` | ||
```bash | ||
git clone git@github.com:nkbt/react-interval.git | ||
cd react-interval | ||
npm install | ||
npm start dev | ||
# then | ||
open http://localhost:8080 | ||
``` | ||
## Tests | ||
```bash | ||
# to run tests | ||
npm start test | ||
# to generate test coverage (./reports/coverage) | ||
npm start test.cov | ||
# to run end-to-end tests | ||
npm start test.e2e | ||
``` | ||
## License | ||
MIT |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
export const ReactInterval = React.createClass({ | ||
propTypes: { | ||
callback: React.PropTypes.func.isRequired, | ||
enabled: React.PropTypes.bool, | ||
timeout: React.PropTypes.number | ||
}, | ||
export class ReactInterval extends React.Component { | ||
static defaultProps = { | ||
enabled: false, | ||
timeout: 1000 | ||
}; | ||
static propTypes = { | ||
callback: PropTypes.func.isRequired, | ||
enabled: PropTypes.bool, | ||
timeout: PropTypes.number | ||
}; | ||
getDefaultProps() { | ||
return { | ||
enabled: false, | ||
timeout: 1000 | ||
}; | ||
}, | ||
componentDidMount() { | ||
@@ -24,5 +21,4 @@ if (this.props.enabled) { | ||
} | ||
}, | ||
} | ||
shouldComponentUpdate({timeout, callback, enabled}) { | ||
@@ -34,5 +30,4 @@ return ( | ||
); | ||
}, | ||
} | ||
componentDidUpdate({enabled}) { | ||
@@ -46,11 +41,9 @@ if (this.props.enabled !== enabled) { | ||
} | ||
}, | ||
} | ||
componentWillUnmount() { | ||
this.stop(); | ||
}, | ||
} | ||
callback() { | ||
callback = () => { | ||
if (this.timer) { | ||
@@ -60,20 +53,17 @@ this.props.callback(); | ||
} | ||
}, | ||
}; | ||
start() { | ||
start = () => { | ||
this.stop(); | ||
this.timer = setTimeout(this.callback, this.props.timeout); | ||
}, | ||
}; | ||
stop() { | ||
stop = () => { | ||
clearTimeout(this.timer); | ||
this.timer = null; | ||
}, | ||
}; | ||
render() { | ||
return false; | ||
} | ||
}); | ||
} |
@@ -1,7 +0,4 @@ | ||
'use strict'; | ||
const {ReactInterval} = require(`./Component`); | ||
const ReactInterval = require('./Component').ReactInterval; | ||
ReactInterval.ReactInterval = ReactInterval; | ||
module.exports = ReactInterval; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
20491
2
9
315
132
2
1
+ Addedprop-types@^15.5.10