Skip to content

Conversation

@juggledad
Copy link

the reset if will fail it msg.reset is a zero because msg.reset will evaluate to FALSE. This change will check to see if msg.reset is a number and then continue if it is.

the reset if will fail it msg.reset is a zero because msg.reset will evaluate to FALSE. This change will check to see if msg.reset is a number and then continue if it is.
@dkern
Copy link
Owner

dkern commented Jun 12, 2019

Thank you for your PR. You are correct, there is a bug. But your "fix" will is make impossible to use msg.reset = true, what should work too. Maybe somehow like this:

if( msg.hasOwnProperty("reset") && (typeof msg.reset === "number" || msg.reset === true) {

@michaelblight
Copy link

I was just going to do my own PR and then saw this. I tested the code below with reset set to true, false, 0, 1, and 5. The only change is to remove && msg.reset from the if (since 0 evaluates as false). Note that according to the documentation, if reset is set to anything other than a number it will reset. Therefore reset being set to false should do the same as reset set to true. I'm not sure if this is really what you would expect, but it does match the documentation.

msg.hasReset = msg.hasOwnProperty("reset");
msg.isNumber = false;
msg.resetType = "Unknown";

if( msg.hasOwnProperty("reset") ) {
    msg.isNumber = typeof msg.reset === "number";
    msg.resetType = typeof msg.reset;
    msg.count = typeof msg.reset === "number" ? "Reset" : "Init";
}
return msg;

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.

3 participants