mirror of
https://github.com/google/blockly.git
synced 2026-01-06 00:20:37 +01:00
chore: Reduce delta on ports to blockly-samples (#6886)
* Reduce usage of obsolete .keyCode property.
* Rename private properties/methods which violate eslint rules.
* Use arrays of bound events rather than individual properties.
* Improve typing info.
* Also fix O(n^2) recursive performance issue in theme's getComponentStyle function.
* And replace String(...) with '${...}' (smaller, faster).
* .toString() is considered harmful.
This commit is contained in:
@@ -62,23 +62,23 @@ export class FieldVariable extends FieldDropdown {
|
||||
* Also accepts Field.SKIP_SETUP if you wish to skip setup (only used by
|
||||
* subclasses that want to handle configuration and setting the field value
|
||||
* after their own constructors have run).
|
||||
* @param opt_validator A function that is called to validate changes to the
|
||||
* @param validator A function that is called to validate changes to the
|
||||
* field's value. Takes in a variable ID & returns a validated variable
|
||||
* ID, or null to abort the change.
|
||||
* @param opt_variableTypes A list of the types of variables to include in the
|
||||
* dropdown. Will only be used if opt_config is not provided.
|
||||
* @param opt_defaultType The type of variable to create if this field's value
|
||||
* is not explicitly set. Defaults to ''. Will only be used if opt_config
|
||||
* @param variableTypes A list of the types of variables to include in the
|
||||
* dropdown. Will only be used if config is not provided.
|
||||
* @param defaultType The type of variable to create if this field's value
|
||||
* is not explicitly set. Defaults to ''. Will only be used if config
|
||||
* is not provided.
|
||||
* @param opt_config A map of options used to configure the field.
|
||||
* @param config A map of options used to configure the field.
|
||||
* See the [field creation documentation]{@link
|
||||
* https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/variable#creation}
|
||||
* for a list of properties this parameter supports.
|
||||
*/
|
||||
constructor(
|
||||
varName: string|null|Sentinel, opt_validator?: FieldVariableValidator,
|
||||
opt_variableTypes?: string[], opt_defaultType?: string,
|
||||
opt_config?: FieldVariableConfig) {
|
||||
varName: string|null|Sentinel, validator?: FieldVariableValidator,
|
||||
variableTypes?: string[], defaultType?: string,
|
||||
config?: FieldVariableConfig) {
|
||||
super(Field.SKIP_SETUP);
|
||||
|
||||
/**
|
||||
@@ -101,13 +101,13 @@ export class FieldVariable extends FieldDropdown {
|
||||
return;
|
||||
}
|
||||
|
||||
if (opt_config) {
|
||||
this.configure_(opt_config);
|
||||
if (config) {
|
||||
this.configure_(config);
|
||||
} else {
|
||||
this.setTypes_(opt_variableTypes, opt_defaultType);
|
||||
this.setTypes_(variableTypes, defaultType);
|
||||
}
|
||||
if (opt_validator) {
|
||||
this.setValidator(opt_validator);
|
||||
if (validator) {
|
||||
this.setValidator(validator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,19 +315,19 @@ export class FieldVariable extends FieldDropdown {
|
||||
/**
|
||||
* Ensure that the ID belongs to a valid variable of an allowed type.
|
||||
*
|
||||
* @param opt_newValue The ID of the new variable to set.
|
||||
* @param newValue The ID of the new variable to set.
|
||||
* @returns The validated ID, or null if invalid.
|
||||
*/
|
||||
protected override doClassValidation_(opt_newValue?: AnyDuringMigration):
|
||||
string|null {
|
||||
if (opt_newValue === null) {
|
||||
protected override doClassValidation_(newValue?: AnyDuringMigration): string
|
||||
|null {
|
||||
if (newValue === null) {
|
||||
return null;
|
||||
}
|
||||
const block = this.getSourceBlock();
|
||||
if (!block) {
|
||||
throw new UnattachedFieldError();
|
||||
}
|
||||
const newId = opt_newValue as string;
|
||||
const newId = newValue as string;
|
||||
const variable = Variables.getVariable(block.workspace, newId);
|
||||
if (!variable) {
|
||||
console.warn(
|
||||
@@ -410,23 +410,19 @@ export class FieldVariable extends FieldDropdown {
|
||||
* Parse the optional arguments representing the allowed variable types and
|
||||
* the default variable type.
|
||||
*
|
||||
* @param opt_variableTypes A list of the types of variables to include in the
|
||||
* @param variableTypes A list of the types of variables to include in the
|
||||
* dropdown. If null or undefined, variables of all types will be
|
||||
* displayed in the dropdown.
|
||||
* @param opt_defaultType The type of the variable to create if this field's
|
||||
* @param defaultType The type of the variable to create if this field's
|
||||
* value is not explicitly set. Defaults to ''.
|
||||
*/
|
||||
private setTypes_(opt_variableTypes?: string[], opt_defaultType?: string) {
|
||||
private setTypes_(variableTypes: string[]|null = null, defaultType = '') {
|
||||
// If you expected that the default type would be the same as the only entry
|
||||
// in the variable types array, tell the Blockly team by commenting on
|
||||
// #1499.
|
||||
const defaultType = opt_defaultType || '';
|
||||
let variableTypes;
|
||||
// Set the allowable variable types. Null means all types on the workspace.
|
||||
if (opt_variableTypes === null || opt_variableTypes === undefined) {
|
||||
variableTypes = null;
|
||||
} else if (Array.isArray(opt_variableTypes)) {
|
||||
variableTypes = opt_variableTypes;
|
||||
if (Array.isArray(variableTypes)) {
|
||||
variableTypes = variableTypes;
|
||||
// Make sure the default type is valid.
|
||||
let isInArray = false;
|
||||
for (let i = 0; i < variableTypes.length; i++) {
|
||||
@@ -439,7 +435,7 @@ export class FieldVariable extends FieldDropdown {
|
||||
'Invalid default type \'' + defaultType + '\' in ' +
|
||||
'the definition of a FieldVariable');
|
||||
}
|
||||
} else {
|
||||
} else if (variableTypes !== null) {
|
||||
throw Error(
|
||||
'\'variableTypes\' was not an array in the definition of ' +
|
||||
'a FieldVariable');
|
||||
|
||||
Reference in New Issue
Block a user