Skip to content

Conversation

@wmertens
Copy link

@wmertens wmertens commented Sep 4, 2019

I mistakenly assumed that 0.5 rps would work…

Copy link
Collaborator

@OlliV OlliV left a comment

Choose a reason for hiding this comment

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

If nr would be set to null this would happen: null | 0 === 0

capacity?: number;
} = {}
) {
if ((nr | 0) !== nr) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if ((nr | 0) !== nr) {
if (nr && !Number.isInteger(nr)) {

Copy link
Author

@wmertens wmertens Sep 19, 2019

Choose a reason for hiding this comment

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

actually, nr should be a positive non-zero integer, so how about if (!nr || nr < 1 || (nr | 0) !== nr)?

Number.isInteger doesn't exist in IE, but maybe that's not an issue?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point, that seems good to me!

Oh no, I didn't thought about that. The polyfill is actually quite simple:

Number.isInteger = Number.isInteger || function(value) {
  return typeof value === 'number' && 
    isFinite(value) && 
    Math.floor(value) === value;
};

Of course we shouldn't actually polyfill it but maybe just do these checks in the if clause.

Number.isFinite() seems to have an implemented in all browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants