raf-throttle
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -6,12 +6,27 @@ ## [HEAD] | ||
## [V2.0.0] | ||
> March 15, 2015 | ||
## [v2.0.3] | ||
> July 14, 2017 | ||
- Preserver `this`. ([@QuentinRoy](https://github.com/QuentinRoy) in [#36](https://github.com/wuct/raf-throttle/pull/36)) | ||
[v2.0.3]: https://github.com/wuct/raf-throttle/compare/v2.0.3...v2.0.2 | ||
## [v2.0.2] | ||
> March 15, 2017 | ||
- Fix umd/rafThrottle.min.js. | ||
[v2.0.2]: https://github.com/wuct/raf-throttle/compare/v2.0.2...v2.0.0 | ||
## [v2.0.0] | ||
> March 15, 2017 | ||
- 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. | ||
- __Breaking:__ Remove `raf` dependency. You will need to add polyfill for it, if you want to support old browsers. ([@bfred-it](https://github.com/bfred-it) in [#16](https://github.com/wuct/raf-throttle/pull/16)) | ||
[v2.0.0]: https://github.com/wuct/raf-throttle/compare/v2.0.0...v1.1.1 | ||
[v1.1.1]: https://github.com/wuct/raf-throttle/compare/v2.0.0...v1.1.1 | ||
## [v1.1.1] | ||
@@ -18,0 +33,0 @@ > April 16, 2016 |
@@ -6,12 +6,9 @@ "use strict"; | ||
}); | ||
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) { | ||
var later = function later(context, args) { | ||
return function () { | ||
requestId = null; | ||
callback.apply(undefined, _toConsumableArray(args)); | ||
callback.apply(context, args); | ||
}; | ||
@@ -21,8 +18,8 @@ }; | ||
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 === undefined) { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
if (requestId == null) { | ||
requestId = requestAnimationFrame(later(args)); | ||
requestId = requestAnimationFrame(later(this, args)); | ||
} | ||
@@ -29,0 +26,0 @@ }; |
{ | ||
"name": "raf-throttle", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Throttle a function by requestAnimationFrame", | ||
@@ -34,7 +34,7 @@ "main": "lib/rafThrottle.js", | ||
"devDependencies": { | ||
"ava": "^0.18.1", | ||
"ava": "^0.20.0", | ||
"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-babili": "0.1.4", | ||
"babel-preset-es2015": "^6.6.0", | ||
@@ -44,3 +44,3 @@ "babel-preset-stage-0": "^6.5.0", | ||
"codecov": "^2.0.1", | ||
"nyc": "^10.0.0", | ||
"nyc": "^11.0.1", | ||
"raf": "^3.2.0", | ||
@@ -47,0 +47,0 @@ "sinon": "^2.0.0", |
const rafThrottle = callback => { | ||
let requestId | ||
const later = args => () => { | ||
const later = (context, args) => () => { | ||
requestId = null | ||
callback(...args) | ||
callback.apply(context, args) | ||
} | ||
const throttled = (...args) => { | ||
if (requestId == null) { | ||
requestId = requestAnimationFrame(later(args)) | ||
const throttled = function(...args) { | ||
if ((requestId === null) || (requestId === undefined)) { | ||
requestId = requestAnimationFrame(later(this, args)) | ||
} | ||
@@ -13,0 +13,0 @@ } |
@@ -12,2 +12,4 @@ # raf-throttle | ||
## [Demo](https://jsfiddle.net/mxbnpwp0/) | ||
## Installation | ||
@@ -14,0 +16,0 @@ |
@@ -19,22 +19,9 @@ (function (global, factory) { | ||
}); | ||
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) { | ||
var later = function later(context, args) { | ||
return function () { | ||
requestId = null; | ||
callback.apply(undefined, _toConsumableArray(args)); | ||
callback.apply(context, args); | ||
}; | ||
@@ -44,8 +31,8 @@ }; | ||
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 === undefined) { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
if (requestId == null) { | ||
requestId = requestAnimationFrame(later(args)); | ||
requestId = requestAnimationFrame(later(this, args)); | ||
} | ||
@@ -52,0 +39,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
(function(global,factory){if(typeof define==="function"&&define.amd){define(["module","exports"],factory)}else if(typeof exports!=="undefined"){factory(module,exports)}else{var mod={exports:{}};factory(mod,mod.exports);global.rafThrottle=mod.exports}})(this,function(module,exports){"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;module.exports=exports["default"]}); | ||
(function(global,factory){if(typeof define==="function"&&define.amd){define(["module","exports"],factory)}else if(typeof exports!=="undefined"){factory(module,exports)}else{var mod={exports:{}};factory(mod,mod.exports);global.rafThrottle=mod.exports}})(this,function(module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var rafThrottle=function rafThrottle(callback){var requestId=void 0;var later=function later(context,args){return function(){requestId=null;callback.apply(context,args)}};var throttled=function throttled(){if(requestId===null||requestId===undefined){for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}requestId=requestAnimationFrame(later(this,args))}};throttled.cancel=function(){return cancelAnimationFrame(requestId)};return throttled};exports.default=rafThrottle;module.exports=exports["default"]}); |
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
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
10413
112
82