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

Make sure we parseInt to avoid concatenating rather than adding. Also… #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TomMettam
Copy link

Make sure we parseInt to avoid concatenating rather than arithmetic.

Also, add ng-bitwise attribute to indicate we should use bitwise-safe operations (3 + 1 = 4, but 3 | 1 = 3). This will matter if the model is being altered elsewhere.

…, add ng-bitwise attribute to indicate we should use bitwise-safe operations (3 + 1 = 4, but 3 | 1 = 3)
@jvdvleuten
Copy link
Owner

Could you provide a better example of what you are trying to accomplish with the bitwise-safe operations?

@jvdvleuten
Copy link
Owner

I will accept the parseInt change btw :)

@TomMettam
Copy link
Author

The problem is the digest chain. Because Angular will only digest the model once per update, it's entirely possible that something else in the chain will modify the model.

If you have flag A = 1, flag B = 2, flag C = 4, and the user activates flag A. Something else in the digest chain modifies existing model and sets it to "1" BEFORE the enum-flag code runs. Then, your arithmetic will change the value to "2" rather than leaving it as "1" which is the correct operation. That's what is meant by "bitwise-safe".

However, obviously this is not appropriate if the flags are not a bitfield (not powers of 2)

@jvdvleuten
Copy link
Owner

Shouldn't it always do that then? Just make it standard? Looks like I didn't thought it through well enough ;)

@TomMettam
Copy link
Author

Well, the reason why I didn't think you'd want to do it as standard, is if you have a non-bitwise enum.. like 1,2,3,4,5.. rather than powers of 2.. 1,2,4,8,16,etc then the bitwise math wouldn't work. So it depends if you want this directive to be bitwise-only, or not.

Actually, thinking about it, that doesn't make sense. There's no reason why anyone would want to sum values in a non-bitwise enum.

So yeah, just make it standard.

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