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

requestanimationframe-timer

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

requestanimationframe-timer - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

dist/index.d.ts

14

CHANGELOG.md

@@ -5,2 +5,16 @@ # Changelog

## [3.0.0](https://github.com/kambing86/requestanimationframe-timer/compare/v2.0.0...v3.0.0) (2020-01-08)
### ⚠ BREAKING CHANGES
* commonjs must use require('requestanimationframe-timer').default
### Bug Fixes
* performance tweak ([3852b08](https://github.com/kambing86/requestanimationframe-timer/commit/3852b089910afa74aecd439c08ab94f2db5b84d6))
* use typescript ([6c7caff](https://github.com/kambing86/requestanimationframe-timer/commit/6c7caff1a38c7fd5230b6aaca171fd3fd78f4182))
## [2.0.0](https://github.com/kambing86/requestanimationframe-timer/compare/v1.0.5...v2.0.0) (2019-12-30)

@@ -7,0 +21,0 @@

167

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _raf = _interopRequireDefault(require("raf"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const MODE_TIMEOUT = 0;
const MODE_INTERVAL = 1;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const raf_1 = __importDefault(require("raf"));
var MODE;
(function (MODE) {
MODE[MODE["MODE_TIMEOUT"] = 0] = "MODE_TIMEOUT";
MODE[MODE["MODE_INTERVAL"] = 1] = "MODE_INTERVAL";
})(MODE || (MODE = {}));
const fnStacks = new Map();

@@ -18,105 +16,70 @@ const runArray = new Set();

let startId = 0;
function getTimeStamp() {
return new Date().getTime();
return new Date().getTime();
}
function executeFn(value) {
const {
fn,
args
} = value;
fn(...args);
const { fn, args } = value;
fn(...args);
}
function runFunction() {
if (runArray.size === 0) return;
runArray.forEach(executeFn);
runArray.clear();
if (runArray.size === 0)
return;
runArray.forEach(executeFn);
runArray.clear();
}
const checkTick = currentTimeTick => (value, id) => {
const {
nextTick,
ms,
mode
} = value;
if (currentTimeTick - nextTick >= 0) {
runArray.add(value);
if (mode === MODE_TIMEOUT) {
fnStacks.delete(id);
} else {
fnStacks.set(id, { ...value,
nextTick: nextTick + ms
});
const checkTick = (currentTimeTick) => (value, id) => {
const { nextTick, ms, mode } = value;
if (currentTimeTick - nextTick >= 0) {
runArray.add(value);
if (mode === MODE.MODE_TIMEOUT) {
fnStacks.delete(id);
}
else {
fnStacks.set(id, Object.assign(Object.assign({}, value), { nextTick: nextTick + ms }));
}
}
}
};
function loop() {
const currentTimeTick = getTimeStamp();
fnStacks.forEach(checkTick(currentTimeTick));
runFunction();
if (fnStacks.size === 0) {
rafStarted = false;
return;
}
(0, _raf.default)(loop);
if (fnStacks.size === 0) {
rafStarted = false;
return;
}
const currentTimeTick = getTimeStamp();
fnStacks.forEach(checkTick(currentTimeTick));
runFunction();
if (fnStacks.size === 0) {
rafStarted = false;
return;
}
raf_1.default(loop);
}
function addId({
fn,
ms = 0,
args,
mode
}) {
if (!fn) return null;
const currentId = startId;
fnStacks.set(currentId, {
fn,
ms,
nextTick: getTimeStamp() + ms,
args,
mode
});
if (!rafStarted) {
rafStarted = true;
(0, _raf.default)(loop);
}
startId += 1;
return currentId;
function addId({ fn, ms, args, mode }) {
if (!fn)
return null;
const currentId = startId;
fnStacks.set(currentId, {
fn,
ms,
nextTick: getTimeStamp() + ms,
args,
mode,
});
if (!rafStarted) {
rafStarted = true;
raf_1.default(loop);
}
startId += 1;
return currentId;
}
function removeId(id) {
if (fnStacks.has(id)) {
fnStacks.delete(id);
}
if (fnStacks.size === 0) {
rafStarted = false;
}
if (fnStacks.has(id)) {
fnStacks.delete(id);
}
}
var _default = {
setTimeout: (fn, ms = 0, ...args) => addId({
fn,
ms,
args,
mode: MODE_TIMEOUT
}),
clearTimeout: removeId,
setInterval: (fn, ms = 0, ...args) => addId({
fn,
ms,
args,
mode: MODE_INTERVAL
}),
clearInterval: removeId
exports.default = {
setTimeout: (fn, ms = 0, ...args) => addId({ fn, ms, args, mode: MODE.MODE_TIMEOUT }),
clearTimeout: removeId,
setInterval: (fn, ms = 0, ...args) => addId({ fn, ms, args, mode: MODE.MODE_INTERVAL }),
clearInterval: removeId,
};
exports.default = _default;
//# sourceMappingURL=index.js.map
{
"name": "requestanimationframe-timer",
"version": "2.0.0",
"version": "3.0.0",
"description": "setTimeout and setInterval by using requestAnimationFrame",

@@ -18,5 +18,7 @@ "keywords": [

"files": [
"dist"
"dist",
"module"
],
"main": "dist/cjs.js",
"main": "dist/index.js",
"module": "module/index.js",
"repository": {

@@ -28,10 +30,15 @@ "type": "git",

"prebuild": "npm run clean",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'",
"build": "tsc --declaration && tsc --declaration -p tsconfig-module.json",
"build:strict": "tsc --declaration --noImplicitAny && tsc --declaration -p tsconfig-module.json --noImplicitAny",
"clean": "del-cli dist",
"lint": "eslint src test",
"lint-staged": "lint-staged",
"prepublish": "npm run build",
"prerelease": "yarn build",
"release": "standard-version",
"security": "./scripts/security.sh",
"start": "npm run build -- -w"
"start": "npm run build -- -w",
"lint": "tslint 'src/**/*.{j,t}s{,x}' && eslint 'src/**/*.{j,t}s{,x}'",
"lint:fix": "tslint --fix 'src/**/*.{j,t}s{,x}' && eslint --fix 'src/**/*.{j,t}s{,x}'",
"prettier": "prettier --check 'src/**/*.*'",
"prettier:write": "prettier --write 'src/**/*.*'"
},

@@ -43,13 +50,20 @@ "pre-commit": "lint-staged",

"devDependencies": {
"@babel/cli": "^7.7.7",
"@babel/core": "^7.7.7",
"@babel/preset-env": "^7.7.7",
"cross-env": "^6.0.3",
"@types/node": "^13.1.4",
"@types/raf": "^3.4.0",
"@typescript-eslint/eslint-plugin": "^2.15.0",
"@typescript-eslint/eslint-plugin-tslint": "^2.15.0",
"@typescript-eslint/parser": "^2.15.0",
"del-cli": "^3.0.0",
"eslint": "^4.19.1",
"eslint-config-webpack": "^1.2.5",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-prettier": "^3.1.2",
"lint-staged": "^9.5.0",
"pre-commit": "^1.2.2",
"standard-version": "^7.0.1"
"prettier": "^1.19.1",
"standard-version": "^7.0.1",
"tslint": "^5.20.1",
"tslint-microsoft-contrib": "^6.2.0",
"typescript": "^3.7.4"
},

@@ -59,9 +73,3 @@ "engines": {

},
"email": "kambing860210@gmail.com",
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
}
"email": "kambing860210@gmail.com"
}
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