raf-throttle
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
| var rafThrottle = function rafThrottle(callback) { | ||
| var requestId = void 0; | ||
| var later = function later(args) { | ||
| return function () { | ||
| requestId = null; | ||
| callback.apply(undefined, _toConsumableArray(args)); | ||
| }; | ||
| }; | ||
| var throttled = function throttled() { | ||
| for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
| args[_key] = arguments[_key]; | ||
| } | ||
| if (requestId == null) { | ||
| requestId = requestAnimationFrame(later(args)); | ||
| } | ||
| }; | ||
| throttled.cancel = function () { | ||
| return cancelAnimationFrame(requestId); | ||
| }; | ||
| return throttled; | ||
| }; | ||
| exports.default = rafThrottle; |
| const rafThrottle = callback => { | ||
| let requestId | ||
| const later = args => () => { | ||
| requestId = null | ||
| callback(...args) | ||
| } | ||
| const throttled = (...args) => { | ||
| if (requestId == null) { | ||
| requestId = requestAnimationFrame(later(args)) | ||
| } | ||
| } | ||
| throttled.cancel = () => | ||
| cancelAnimationFrame(requestId) | ||
| return throttled | ||
| } | ||
| export default rafThrottle |
| (function(a,b){if("function"==typeof define&&define.amd)define(["module","exports"],b);else if("undefined"!=typeof exports)b(module,exports);else{var c={exports:{}};b(c,c.exports),a.rafThrottle=c.exports}})(this,function(a,b){"use strict";var _arguments=arguments;function c(e){if(Array.isArray(e)){for(var f=0,g=Array(e.length);f<e.length;f++)g[f]=e[f];return g}return Array.from(e)}Object.defineProperty(b,"__esModule",{value:!0});b.default=function rafThrottle(e){var f,g=function later(j){return function(){f=null,e.apply(void 0,c(j))}},h=function throttled(){for(var j=_arguments.length,k=Array(j),l=0;l<j;l++)k[l]=_arguments[l];null==f&&(f=requestAnimationFrame(g(k)))};return h.cancel=function(){return cancelAnimationFrame(f)},h},a.exports=b["default"]}); |
+1
-3
| language: node_js | ||
| node_js: | ||
| - "5" | ||
| - "4" | ||
| - "0.12" | ||
| - "node" | ||
| before_install: | ||
@@ -7,0 +5,0 @@ - npm install -g npm |
+11
-0
@@ -5,2 +5,13 @@ ## [HEAD] | ||
| ## [V2.0.0] | ||
| > March 15, 2015 | ||
| - Support for UMD build. Now we can use rafThrottle from CDN. ✌️ | ||
| - __Breaking:__ Remove `raf` dependency. You will need to add polyfill for it, if you want to support old browsers. | ||
| [v1.1.1]: https://github.com/wuct/raf-throttle/compare/v2.0.0...v1.1.1 | ||
| ## [v1.1.1] | ||
@@ -7,0 +18,0 @@ > April 16, 2016 |
+16
-11
| { | ||
| "name": "raf-throttle", | ||
| "version": "1.1.1", | ||
| "version": "2.0.0", | ||
| "description": "Throttle a function by requestAnimationFrame", | ||
| "main": "lib/index.js", | ||
| "main": "lib/rafThrottle.js", | ||
| "scripts": { | ||
| "test": "ava --timeout 10000", | ||
| "test:coverage": "nyc npm test", | ||
| "coverage": "nyc report --reporter=text-lcov | codecov", | ||
| "build": "NODE_ENV=production babel index.js --out-dir lib", | ||
| "coverage": "nyc report --reporter=lcov > coverage.lcov && codecov", | ||
| "clean": "rm -rf lib & rm -rf umd", | ||
| "build:CommonJS": "NODE_ENV=production babel --out-dir lib rafThrottle.js", | ||
| "build:UMD": "mkdir umd && NODE_ENV=umd babel --out-file umd/rafThrottle.min.js rafThrottle.js", | ||
| "build": "npm run build:CommonJS & npm run build:UMD", | ||
| "prebuild": "npm run clean", | ||
| "prepublish": "npm run build" | ||
@@ -29,14 +33,15 @@ }, | ||
| "devDependencies": { | ||
| "ava": "^0.14.0", | ||
| "ava": "^0.18.1", | ||
| "babel-cli": "^6.7.5", | ||
| "babel-plugin-add-module-exports": "^0.2.1", | ||
| "babel-plugin-transform-es2015-modules-umd": "^6.24.0", | ||
| "babel-preset-babili": "0.0.12", | ||
| "babel-preset-es2015": "^6.6.0", | ||
| "babel-preset-stage-0": "^6.5.0", | ||
| "babel-register": "^6.6.5", | ||
| "codecov.io": "^0.1.6", | ||
| "nyc": "^6.1.1", | ||
| "sinon": "^1.17.3" | ||
| "codecov": "^2.0.1", | ||
| "nyc": "^10.0.0", | ||
| "raf": "^3.2.0", | ||
| "sinon": "^2.0.0" | ||
| }, | ||
| "dependencies": { | ||
| "raf": "^3.2.0" | ||
| }, | ||
| "ava": { | ||
@@ -43,0 +48,0 @@ "files": [ |
+17
-2
@@ -14,6 +14,22 @@ # raf-throttle | ||
| ### npm | ||
| `npm install raf-throttle --save` | ||
| ### yarn | ||
| `yarn add raf-throttle` | ||
| ### CDN | ||
| Download the file from [https://unpkg.com/raf-throttle/umd/rafThrottle.min.js](), | ||
| and consume it from global as `rafThrottle`. | ||
| ## Usage | ||
| ### Polyfill | ||
| Since [most of browsers](http://caniuse.com/#feat=requestanimationframe) support `requestAnimationFrame` by default, you can use `raf-throttle` directly. However, if you want to support old browsers, you will need to polyfill `requestAnimationFrame` by youself. One option is using [`raf`](https://www.npmjs.com/package/raf). | ||
| ### Example | ||
@@ -67,3 +83,3 @@ | ||
| ```js | ||
| const throttled = throttle(foo) | ||
| const throttled = throttle(foo) | ||
| throttled() | ||
@@ -96,2 +112,1 @@ throttled.cancel() // foo would never be invoked | ||
| ## [LICENSE](LICENSE) | ||
| {"/Users/mtk10835/raf-throttle/index.js":{"path":"/Users/mtk10835/raf-throttle/index.js","s":{"1":1,"2":1,"3":4,"4":4,"5":4,"6":4,"7":4,"8":8,"9":5,"10":4,"11":4},"b":{"1":[5,3]},"f":{"1":4,"2":5,"3":4,"4":8,"5":1},"fnMap":{"1":{"name":"rafThrottle","line":3,"loc":{"start":{"line":3,"column":20},"end":{"line":3,"column":32}}},"2":{"name":"later","line":6,"loc":{"start":{"line":6,"column":16},"end":{"line":null,"column":-1}}},"3":{"name":"(anonymous_5)","line":6,"loc":{"start":{"line":6,"column":24},"end":{"line":6,"column":30}}},"4":{"name":"throttled","line":11,"loc":{"start":{"line":11,"column":20},"end":{"line":11,"column":33}}},"5":{"name":"(anonymous_7)","line":17,"loc":{"start":{"line":17,"column":21},"end":{"line":null,"column":-1}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":null,"column":-1}},"2":{"start":{"line":3,"column":0},"end":{"line":3,"column":20}},"3":{"start":{"line":4,"column":2},"end":{"line":3,"column":32}},"4":{"start":{"line":6,"column":2},"end":{"line":3,"column":32}},"5":{"start":{"line":7,"column":4},"end":{"line":6,"column":30}},"6":{"start":{"line":8,"column":4},"end":{"line":6,"column":30}},"7":{"start":{"line":11,"column":2},"end":{"line":3,"column":32}},"8":{"start":{"line":12,"column":4},"end":{"line":12,"column":3}},"9":{"start":{"line":13,"column":6},"end":{"line":12,"column":27}},"10":{"start":{"line":17,"column":2},"end":{"line":3,"column":32}},"11":{"start":{"line":20,"column":2},"end":{"line":3,"column":32}}},"branchMap":{"1":{"line":12,"type":"if","locations":[{"start":{"line":12,"column":4},"end":{"line":12,"column":7}},{"start":{"line":12,"column":4},"end":{"line":12,"column":7}}]}}}} |
-42
| 'use strict'; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| var _raf = require('raf'); | ||
| var _raf2 = _interopRequireDefault(_raf); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
| var rafThrottle = function rafThrottle(callback) { | ||
| var requestId = void 0; | ||
| var later = function later(args) { | ||
| return function () { | ||
| requestId = null; | ||
| callback.apply(undefined, _toConsumableArray(args)); | ||
| }; | ||
| }; | ||
| var throttled = function throttled() { | ||
| for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
| args[_key] = arguments[_key]; | ||
| } | ||
| if (requestId == null) { | ||
| requestId = (0, _raf2.default)(later(args)); | ||
| } | ||
| }; | ||
| throttled.cancel = function () { | ||
| return _raf2.default.cancel(requestId); | ||
| }; | ||
| return throttled; | ||
| }; | ||
| exports.default = rafThrottle; |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
8530
5.91%0
-100%8
14.29%45
55.17%110
15.79%12
50%1
Infinity%- Removed
- Removed
- Removed