-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
chore: cleaned up several type cases in core/field.ts and impacted files #6363
Conversation
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.
LGTM! It is frustrating that so many of these things have to be nullable, but I think that's a problem with the design of the field, not with this change.
One question: How would you feel about changing instances of sourceBlock_!
to use getSourceBlock()
instead (which already includes the assertion).
I'm 100% for it! |
ffebb56
to
2138e80
Compare
@BeksOmega all set! I updated |
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.
Thanks for your work on this dude!
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.
Rebase/merge (your preference) to resolve conflicts, then I think this is gtg.
58a6045
to
9396432
Compare
My tests are broken locally even at |
d990457
to
b5aac27
Compare
@@ -202,7 +202,7 @@ export class FieldAngle extends FieldTextInput { | |||
// #2380) | |||
this.symbol_ = dom.createSvgElement(Svg.TSPAN, {}); | |||
this.symbol_.appendChild(document.createTextNode('\u00B0')); | |||
this.textElement_.appendChild(this.symbol_); | |||
this.getTextElement().appendChild(this.symbol_); |
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.
Hey @maribethb & @BeksOmega - I went ahead and created getTextElement
and other wrapper functions to handle encapsulating the null error check. What do you think about utilizing it in this context, though? Earlier, it was mentioned using this.textElement_!
made sense here since it was just defined in initView
. The trade off here I think is 'runtime compute' vs 'developer compute', so to speak 😂
Runtime Compute - In cases like this where the null check is so minor, it would take an extreme number of runs for it to impact runtime performance.
Developer Compute - It might be obvious that after initView
the textElement_
should be set, though it's just one less thing a developer has to juggle when looking through this code.
Edit: The main purpose of asking here is the conceptual discussion of how to handle cases like this rather than specifically whether or not I need to correct this case (though I will correct it if this.textElement_!
would be preferred!)
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.
I think either option makes sense in situations like this where we never expect developers to be interacting with these properties while they're 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.
We discussed this earlier this week and this is one of those cases where it's acceptable because it's easily verified that textElement is set directly beforehand in initView. The property is set and then used in the same method so there is no room for developer error - compare that to fieldGroup_
where it could be set in multiple places and an error like forgetting to call an init method would result in the value being unexpectedly null.
There is no hard and fast rule I can give you but that's why this particular case the !
is fine, though using the method is also fine.
b5aac27
to
dd10ba4
Compare
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.
Just gonna wait for @maribethb 's quick lgtm as well.
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.
in general, I would prefer more descriptive error messages that might give you a hint about what has done wrong like "fieldGroup_ is null. Has this field been initialized?" or "You may need to initialize this field first" or something, but that isn't always easy to tell. so don't necessarily need to change these, just something to think about whenever we add these.
@@ -1217,19 +1228,20 @@ export abstract class Field implements IASTNodeLocationSvg, | |||
*/ | |||
setMarkerSvg(markerSvg: SVGElement) { | |||
if (!markerSvg) { |
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.
I think the parameter to this function needs to be nullable, otherwise this check doesn't make sense. some of our other setMarkerSvg
methods have the same logic and the parameter is nullable there. I wonder if this was created from our closure code where we didn't always use ?
consistently
@@ -202,7 +202,7 @@ export class FieldAngle extends FieldTextInput { | |||
// #2380) | |||
this.symbol_ = dom.createSvgElement(Svg.TSPAN, {}); | |||
this.symbol_.appendChild(document.createTextNode('\u00B0')); | |||
this.textElement_.appendChild(this.symbol_); | |||
this.getTextElement().appendChild(this.symbol_); |
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.
We discussed this earlier this week and this is one of those cases where it's acceptable because it's easily verified that textElement is set directly beforehand in initView. The property is set and then used in the same method so there is no room for developer error - compare that to fieldGroup_
where it could be set in multiple places and an error like forgetting to call an init method would result in the value being unexpectedly null.
There is no hard and fast rule I can give you but that's why this particular case the !
is fine, though using the method is also fine.
@btw17 give me a ping when this is ready for another look =) |
dd10ba4
to
23b49f9
Compare
All set now! Just updated this PR to include the latest updates from the |
LGTM after the build passes! If you want to work on this I'll baby sit it to rerun the CI. But don't feel the need to work on it before Friday. |
d98545c
to
d6801da
Compare
The basics
npm run format
andnpm run lint
The details
Resolves
This resolves several
AnyDuringMigration
type cases incore/field.ts
.Proposed Changes
<OriginalType>|null
to properly reflect its possible statecore/field.ts
and impacted descendantssomeValue!.nowExists
callingClass
which uses Field's prototypecore/field.ts
Behavior Before Change
SVGTextElement.setAttribute
passed in numbers as attribute values instead of strings incore/field.ts
Behavior After Change
SVGTextElement.setAttribute
always passes in strings now incore/field.ts
Reason for Changes
Simplifying the information space by offloading type juggling to the compiler.