raf-throttle
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -1,13 +0,11 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var rafThrottle = function rafThrottle(callback) { | ||
var requestId = void 0; | ||
var requestId = null; | ||
var lastArgs; | ||
var later = function later(context, args) { | ||
var later = function later(context) { | ||
return function () { | ||
requestId = null; | ||
callback.apply(context, args); | ||
callback.apply(context, lastArgs); | ||
}; | ||
@@ -17,8 +15,10 @@ }; | ||
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]; | ||
} | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
requestId = requestAnimationFrame(later(this, args)); | ||
lastArgs = args; | ||
if (requestId === null) { | ||
requestId = requestAnimationFrame(later(this)); | ||
} | ||
@@ -28,3 +28,4 @@ }; | ||
throttled.cancel = function () { | ||
return cancelAnimationFrame(requestId); | ||
cancelAnimationFrame(requestId); | ||
requestId = null; | ||
}; | ||
@@ -35,2 +36,2 @@ | ||
exports.default = rafThrottle; | ||
module.exports = rafThrottle; |
{ | ||
"name": "raf-throttle", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Throttle a function by requestAnimationFrame", | ||
"main": "lib/rafThrottle.js", | ||
"scripts": { | ||
"test": "ava --timeout 10000", | ||
"test:coverage": "nyc npm test", | ||
"coverage": "nyc report --reporter=lcov > coverage.lcov && codecov", | ||
"test": "jest --coverage", | ||
"report-coverage": "cat ./coverage/lcov.info | codecov", | ||
"clean": "rm -rf lib & rm -rf umd", | ||
"build:CommonJS": "NODE_ENV=production babel --out-dir lib rafThrottle.js", | ||
"build:UMD": "NODE_ENV=umd babel --out-file umd/rafThrottle.js rafThrottle.js", | ||
"build:minifiedUMD": "uglifyjs -o umd/rafThrottle.min.js umd/rafThrottle.js", | ||
"build": "npm run build:CommonJS && mkdir umd && npm run build:UMD && npm run build:minifiedUMD", | ||
"build": "rollup -c && npm run build:minifiedUMD", | ||
"prebuild": "npm run clean", | ||
"prepublish": "npm run build" | ||
"prepublish": "npm run build", | ||
"semantic-release": "semantic-release" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wuct/raf-throttle.git" | ||
"url": "https://github.com/wuct/raf-throttle.git" | ||
}, | ||
@@ -34,25 +32,18 @@ "keywords": [ | ||
"devDependencies": { | ||
"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.1.4", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"babel-register": "^6.6.5", | ||
"codecov": "^2.0.1", | ||
"nyc": "^11.0.1", | ||
"raf": "^3.2.0", | ||
"sinon": "^2.0.0", | ||
"uglify-js": "^2.8.12" | ||
"@babel/cli": "7.11.6", | ||
"@babel/core": "7.11.6", | ||
"@babel/preset-env": "7.11.5", | ||
"babel-jest": "26.3.0", | ||
"codecov": "3.7.2", | ||
"jest": "26.4.2", | ||
"raf": "3.4.1", | ||
"rollup": "2.26.11", | ||
"rollup-plugin-babel": "4.4.0", | ||
"uglify-js": "3.10.4", | ||
"semantic-release": "^17.1.1" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"test.js" | ||
], | ||
"babel": "inherit", | ||
"require": [ | ||
"babel-register" | ||
] | ||
"jest": { | ||
"coverageDirectory": "./coverage/", | ||
"collectCoverage": true | ||
} | ||
} |
const rafThrottle = callback => { | ||
let requestId | ||
let requestId = null | ||
const later = (context, args) => () => { | ||
let lastArgs | ||
const later = (context) => () => { | ||
requestId = null | ||
callback.apply(context, args) | ||
callback.apply(context, lastArgs) | ||
} | ||
const throttled = function(...args) { | ||
if ((requestId === null) || (requestId === undefined)) { | ||
requestId = requestAnimationFrame(later(this, args)) | ||
lastArgs = args; | ||
if (requestId === null) { | ||
requestId = requestAnimationFrame(later(this)) | ||
} | ||
} | ||
throttled.cancel = () => | ||
throttled.cancel = () => { | ||
cancelAnimationFrame(requestId) | ||
requestId = null | ||
} | ||
@@ -18,0 +23,0 @@ return throttled |
@@ -6,5 +6,4 @@ # raf-throttle | ||
[![npm](https://img.shields.io/npm/v/raf-throttle.svg)](https://www.npmjs.com/package/raf-throttle) | ||
[![Travis](https://img.shields.io/travis/wuct/raf-throttle.svg)](https://travis-ci.org/wuct/raf-throttle) | ||
[![Codecov](https://img.shields.io/codecov/c/github/wuct/raf-throttle.svg)](https://codecov.io/github/wuct/raf-throttle) | ||
[![Code Climate](https://img.shields.io/codeclimate/github/wuct/raf-throttle.svg)](https://codeclimate.com/github/wuct/raf-throttle) | ||
[![Build Status](https://travis-ci.org/wuct/raf-throttle.svg?branch=master)](https://travis-ci.org/wuct/raf-throttle) | ||
[![codecov](https://codecov.io/gh/wuct/raf-throttle/branch/master/graph/badge.svg)](https://codecov.io/gh/wuct/raf-throttle) [![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/) | ||
@@ -27,3 +26,3 @@ [raf-throttle](https://www.npmjs.com/package/raf-throttle) let you create a throttled function, which only invokes the passed function at most once per [animation frame](https://developer.mozilla.org/en/docs/Web/API/window/requestAnimationFrame) on a browser or per 1000/60 ms on Node. | ||
Download the file from [https://unpkg.com/raf-throttle/umd/rafThrottle.min.js](), | ||
Download the file from [https://unpkg.com/raf-throttle/umd/rafThrottle.min.js](https://unpkg.com/raf-throttle/umd/rafThrottle.min.js), | ||
@@ -45,6 +44,6 @@ and consume it from global as `rafThrottle`. | ||
```js | ||
import throttle from 'raf-throttle' | ||
import throttle from 'raf-throttle'; | ||
const throttled = throttle(updatePosition) | ||
window.addEventListener('scroll', throttled) | ||
const throttled = throttle(updatePosition); | ||
window.addEventListener('scroll', throttled); | ||
``` | ||
@@ -55,5 +54,5 @@ | ||
```js | ||
import throttle from 'raf-throttle' | ||
import throttle from 'raf-throttle'; | ||
$(window).on('scroll', throttle(updatePosition)) | ||
$(window).on('scroll', throttle(updatePosition)); | ||
``` | ||
@@ -88,5 +87,5 @@ | ||
```js | ||
const throttled = throttle(foo) | ||
throttled() | ||
throttled.cancel() // foo would never be invoked | ||
const throttled = throttle(foo); | ||
throttled(); | ||
throttled.cancel(); // foo would never be invoked | ||
``` | ||
@@ -97,3 +96,3 @@ | ||
```js | ||
import throttle from 'raf-throttle' | ||
import throttle from 'raf-throttle'; | ||
``` | ||
@@ -111,5 +110,5 @@ | ||
* ⇄ Pull requests and ★ Stars are always welcome. | ||
* For bugs and feature requests, please create an issue. | ||
* Pull requests must be accompanied by passing automated tests (`$ npm test`). | ||
- ⇄ Pull requests and ★ Stars are always welcome. | ||
- For bugs and feature requests, please create an issue. | ||
- Pull requests must be accompanied by passing automated tests (`$ npm test`). | ||
@@ -116,0 +115,0 @@ ## [CHANGELOG](CHANGELOG.md) |
(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"; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.rafThrottle = factory()); | ||
}(this, (function () { 'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var rafThrottle = function rafThrottle(callback) { | ||
var requestId = void 0; | ||
var requestId = null; | ||
var lastArgs; | ||
var later = function later(context, args) { | ||
var later = function later(context) { | ||
return function () { | ||
requestId = null; | ||
callback.apply(context, args); | ||
callback.apply(context, lastArgs); | ||
}; | ||
@@ -30,8 +19,10 @@ }; | ||
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]; | ||
} | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
requestId = requestAnimationFrame(later(this, args)); | ||
lastArgs = args; | ||
if (requestId === null) { | ||
requestId = requestAnimationFrame(later(this)); | ||
} | ||
@@ -41,3 +32,4 @@ }; | ||
throttled.cancel = function () { | ||
return cancelAnimationFrame(requestId); | ||
cancelAnimationFrame(requestId); | ||
requestId = null; | ||
}; | ||
@@ -48,4 +40,4 @@ | ||
exports.default = rafThrottle; | ||
module.exports = exports["default"]; | ||
}); | ||
return rafThrottle; | ||
}))); |
@@ -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});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"]}); | ||
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,global.rafThrottle=factory())})(this,function(){"use strict";var rafThrottle=function rafThrottle(callback){var requestId=null;var lastArgs;var later=function later(context){return function(){requestId=null;callback.apply(context,lastArgs)}};var throttled=function throttled(){for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}lastArgs=args;if(requestId===null){requestId=requestAnimationFrame(later(this))}};throttled.cancel=function(){cancelAnimationFrame(requestId);requestId=null};return throttled};return rafThrottle}); |
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
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
57323
11
24
654
111
1