-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Introduce inheritance to the Parameter structure #4049
Conversation
So far moved all code to their separate files, I still want to revise the methods names (there are several "value" attributes and it would be nice if they were a bit more descriptive on what they do, or at least have comments). Also need to see if something else can be cleaned up. Will continue tomorrow. @kravets-levko and @ranbena lmk if you have inputs here :) |
this.locals = []; | ||
|
||
// Used for URL serialization | ||
Object.defineProperty(this, 'urlPrefix', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Cypress pointed out, this doesn't work with inheritance 🙂
Review of existent values in the Parameter Structure:
From those need to make sure only |
Dynamic Values merged in Regarding values, this is what I've been thinking: (once defined I would also put as comment in the "abstract" Parameter class)
|
I like it a lot. So glad you're doing this :) Thinking about this, in order to make things unmistakable, wdyt of having one value only which can be converted into different formats via static method
It's long, might not be performant, but I'd like to find ways to minimize confusion above all. |
Definitively more readable, the |
Yeah I guess it's meaningless.
You mean performance, yeah? Maybe memoize? |
@ranbena I'm actually thinking about keeping them as variables (updated on @kravets-levko lmk if you have other suggestions for the parameter structure. |
69ea210
to
0374841
Compare
@gabrieldutra I'm working on #2721 and I wanna base it on this PR. If not, maybe consider making |
Cool, @ranbena, I actually want to move forward and merge this soon anyway (will sync it today). For the |
I’m with you on that 👍 Regarding isEmpty - don’t you think it should be allowed to be set by each param type? |
} | ||
|
||
isEmptyValue(value) { | ||
return isNull(this.normalizeValue(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ranbena I've realized I could generalize the "empty" concept like this (ideally invalid values are turned into "null")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great 🎉
Two non-must comments.
if (isNull(value)) { | ||
return null; | ||
} | ||
const normalizedValue = toNumber(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toNumber
converts empty strings to 0, but I think it should be normalized to null
instead.
How about:
import { toNumber, trim } from 'lodash';
normalizeValue(value) {
if (!trim(value)) {
return null;
}
...
}
return normalizedValue; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggesting addition:
isEmptyValue(value) {
return !trim(value);
}
🚢 |
What type of PR is this? (check all applicable)
Description
This is a start of a draft of what I was thinking of how parameters should be in code as we are increasing complexity for them. So far basically started with inheritance, the "abstract" Parameter holds the default methods that will be replaced as needed for the parameters.
This way it's easier to control Parameter valid values and introduce new features to existing parameters or add new types.
Opening this already to gather comments from your ideas.
Fixes #3769