fix: Fire deletion events when clearing variables. (#6827)

https://groups.google.com/g/blockly/c/l_vUnrGSJ0M
This commit is contained in:
Neil Fraser
2023-02-07 21:20:01 +01:00
committed by GitHub
parent 498766b930
commit 90217360c7
2 changed files with 18 additions and 5 deletions

View File

@@ -44,10 +44,18 @@ export class VariableMap {
/** @param workspace The workspace this map belongs to. */
constructor(public workspace: Workspace) {}
/** Clear the variable map. */
/** Clear the variable map. Fires events for every deletion. */
clear() {
this.variableMap.clear();
for (const variables of this.variableMap.values()) {
while (variables.length > 0) {
this.deleteVariable(variables[0]);
}
}
if (this.variableMap.size !== 0) {
throw Error('Non-empty variable map');
}
}
/* Begin functions for renaming variables. */
/**
* Rename the given variable by updating its name in the variable map.
@@ -142,6 +150,7 @@ export class VariableMap {
// And remove it from the list.
arrayUtils.removeElem(this.variableMap.get(type)!, variable);
}
/* End functions for renaming variables. */
/**
* Create a variable with a given name, optional type, and optional ID.
@@ -187,6 +196,7 @@ export class VariableMap {
return variable;
}
/* Begin functions for variable deletion. */
/**
* Delete a variable.
@@ -203,6 +213,9 @@ export class VariableMap {
variableList.splice(i, 1);
eventUtils.fire(
new (eventUtils.get(eventUtils.VAR_DELETE))(variable));
if (variableList.length === 0) {
this.variableMap.delete(variable.type);
}
return;
}
}
@@ -306,7 +319,7 @@ export class VariableMap {
* @returns The variable with the given ID.
*/
getVariableById(id: string): VariableModel|null {
for (const [_key, variables] of this.variableMap) {
for (const variables of this.variableMap.values()) {
for (const variable of variables) {
if (variable.getId() === id) {
return variable;

View File

@@ -102,7 +102,7 @@ function checkReleaseDir(done) {
// Check with the user that the version number is correct, then login and publish to npm.
function loginAndPublish_(done, isBeta) {
const { version } = getPackageJson();
if(readlineSync.keyInYN(`You are about to publish blockly with the version number:${version}. Do you want to continue?`)) {
if (readlineSync.keyInYN(`You are about to publish blockly with the version number:${version}. Do you want to continue?`)) {
execSync(`npm login --registry https://wombat-dressing-room.appspot.com`, {stdio: 'inherit'});
execSync(`npm publish --registry https://wombat-dressing-room.appspot.com ${isBeta ? '--tag beta' : ''}`, {cwd: RELEASE_DIR, stdio: 'inherit'});
done();
@@ -129,7 +129,7 @@ function updateBetaVersion(done) {
const blocklyVersions = JSON.parse(execSync('npm view blockly versions --json').toString());
const re = new RegExp(/-beta\.(\d)/);
const latestBetaVersion = execSync('npm show blockly version --tag beta').toString().trim();
while(!isValid) {
while (!isValid) {
newVersion = readlineSync.question(`What is the new beta version? (latest beta version: ${latestBetaVersion})`);
const existsOnNpm = blocklyVersions.indexOf(newVersion) > -1;
const isFormatted = newVersion.search(re) > -1;