-
Notifications
You must be signed in to change notification settings - Fork 64
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
proposal: refactor conditionals #90
Comments
Hey @GregOnNet, thanks so much for opening this issue and proposing a refactoring for the messy conditional. I really appreciate it. I like the rule-based approach and I also agree that the Also, I need to give the conditionals better names, cause I find it hard after some time to understand what they do without spending a couple of minutes thinking about them 😂 |
Talking about names for rules brings classes to my mind. interface BoxRule {
isMatch: (predicate: boolean) => boolean
}
class InsideBoxRule implements BoxRule {
isMatch(isInBox:boolean, predicate: boolean): boolean {
return isInBox && predicate;
}
}
class OutsideBoxRule implements BoxRule {
isMatch(isInBox:boolean, predicate: boolean): boolean {
return !isInBox && predicate;
} |
Gotcha! Definitely an interesting approach. Thanks for your input, really appreciate it. I ll have to think about this for a while but I might refactor the library to use state machines. I think this is a great way to tame the complexity of this lib including all of its modes and features, as it's getting more and more feature rich and the conditionals are getting out of control. |
Hi,
an idea could be to refactor the conditionals into certain rule lists.
Disclaimer
🤗 This issue is just an idea according to https://twitter.com/elmd_/status/1181875171667451905.
Propsal
Affected code
ngx-drag-to-select/projects/ngx-drag-to-select/src/lib/select-container.component.ts
Lines 423 to 441 in c47dee4
Further thoughts.
The handling of
withinBoundingBox
can be improved.It is a repetitively used.
Maybe
addRules
can be transformed to a list of functions that deal withwithinBoundingBox
The text was updated successfully, but these errors were encountered: