Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent infinity loop when 'particleCount' is negative number. #127

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/confetti.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
);
}

function onlyPositiveInt(number){
return number < 0 ? 0 : Math.floor(number);
}

Comment on lines +209 to +212
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add 'onlyPositiveInt' transform function

function randomInt(min, max) {
// [min, max)
return Math.floor(Math.random() * (max - min)) + min;
Expand Down Expand Up @@ -412,7 +416,7 @@
var animationObj;

function fireLocal(options, size, done) {
var particleCount = prop(options, 'particleCount', Math.floor);
var particleCount = prop(options, 'particleCount', onlyPositiveInt);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use 'onlyPositiveInt' function instead Math.floor

var angle = prop(options, 'angle', Number);
var spread = prop(options, 'spread', Number);
var startVelocity = prop(options, 'startVelocity', Number);
Expand Down