chore: cleaned up several type cases in core/field.ts and impacted files (#6363)

* chore: cleaned up several type cases in core/field.ts and impacted files

* chore: updated instances of `sourceBlock_!` to `getSourceBlock()`

* chore: updated instances of `fieldGroup_!` to `getSvgRoot()`

* chore: updated nullable variables in `field.ts` to use internal functions

* chore: updated getSourceBlock and getSvgRoot to handle nullability

* chore: updated comments to reference throwing an error

* fix: reverted `getSvgRoot` to `fieldGroup_` in null-accepting areas

* fix: updated `getSvgRoot` to allow null and added null handling methods

* fix: moved click target error handling to their specific cases

* fix: updated drawer.ts to handle cast svg group to defined
This commit is contained in:
Blake Thomas Williams
2022-09-30 10:53:19 -05:00
committed by GitHub
parent dd0d0f6bcf
commit fa925e8c35
11 changed files with 151 additions and 124 deletions

View File

@@ -139,7 +139,7 @@ export class FieldVariable extends FieldDropdown {
return; // Initialization already happened.
}
const variable = Variables.getOrCreateVariablePackage(
this.sourceBlock_.workspace, null, this.defaultVariableName,
this.getSourceBlock().workspace, null, this.defaultVariableName,
this.defaultType_);
// Don't call setValue because we don't want to cause a rerender.
this.doValueUpdate_(variable.getId());
@@ -148,7 +148,7 @@ export class FieldVariable extends FieldDropdown {
override shouldAddBorderRect_() {
return super.shouldAddBorderRect_() &&
(!this.getConstants()!.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW ||
this.sourceBlock_.type !== 'variables_get');
this.getSourceBlock().type !== 'variables_get');
}
/**
@@ -168,7 +168,7 @@ export class FieldVariable extends FieldDropdown {
// AnyDuringMigration because: Argument of type 'string | null' is not
// assignable to parameter of type 'string | undefined'.
const variable = Variables.getOrCreateVariablePackage(
this.sourceBlock_.workspace, id, variableName as AnyDuringMigration,
this.getSourceBlock().workspace, id, variableName as AnyDuringMigration,
variableType);
// This should never happen :)
@@ -238,7 +238,7 @@ export class FieldVariable extends FieldDropdown {
}
// This is necessary so that blocks in the flyout can have custom var names.
const variable = Variables.getOrCreateVariablePackage(
this.sourceBlock_.workspace, state['id'] || null, state['name'],
this.getSourceBlock().workspace, state['id'] || null, state['name'],
state['type'] || '');
this.setValue(variable.getId());
}
@@ -316,7 +316,8 @@ export class FieldVariable extends FieldDropdown {
return null;
}
const newId = opt_newValue as string;
const variable = Variables.getVariable(this.sourceBlock_.workspace, newId);
const variable =
Variables.getVariable(this.getSourceBlock().workspace, newId);
if (!variable) {
console.warn(
'Variable id doesn\'t point to a real variable! ' +
@@ -343,7 +344,7 @@ export class FieldVariable extends FieldDropdown {
*/
protected override doValueUpdate_(newId: AnyDuringMigration) {
this.variable_ =
Variables.getVariable(this.sourceBlock_.workspace, newId as string);
Variables.getVariable(this.getSourceBlock().workspace, newId as string);
super.doValueUpdate_(newId);
}