mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-10 15:02:06 -05:00
Rename util function to be more descriptive. Refactor parameters to remove unused code.
This commit is contained in:
parent
7faddb6c8f
commit
d91c19434f
3 changed files with 6 additions and 7 deletions
|
@ -515,7 +515,7 @@ class Target extends EventEmitter {
|
||||||
// for all references for a given ID instead of doing the below..?
|
// for all references for a given ID instead of doing the below..?
|
||||||
this.blocks.getAllVariableAndListReferences()[idToBeMerged];
|
this.blocks.getAllVariableAndListReferences()[idToBeMerged];
|
||||||
|
|
||||||
VariableUtil.mergeVariables(idToBeMerged, idToMergeWith, referencesToChange, optNewName);
|
VariableUtil.updateVariableIdentifiers(referencesToChange, idToMergeWith, optNewName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1160,7 +1160,7 @@ const replaceUnsafeCharsInVariableIds = function (targets) {
|
||||||
// We're calling this on the stage target because we need a
|
// We're calling this on the stage target because we need a
|
||||||
// target to call on but this shouldn't matter because we're passing
|
// target to call on but this shouldn't matter because we're passing
|
||||||
// in all the varRefs we want to operate on
|
// in all the varRefs we want to operate on
|
||||||
VariableUtil.mergeVariables(id, newId, allVarRefs);
|
VariableUtil.updateVariableIdentifiers(allVarRefs[id], newId);
|
||||||
}
|
}
|
||||||
return targets;
|
return targets;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,18 +25,17 @@ class VariableUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge variable references with another variable.
|
* Give all variable references provided a new id and possibly new name.
|
||||||
* @param {string} idToBeMerged ID of the variable whose references need to be updated
|
|
||||||
* @param {string} idToMergeWith ID of the variable that the old references should be replaced with
|
|
||||||
* @param {Array<object>} referencesToUpdate Context of the change, the object containing variable
|
* @param {Array<object>} referencesToUpdate Context of the change, the object containing variable
|
||||||
* references to update.
|
* references to update.
|
||||||
|
* @param {string} newId ID of the variable that the old references should be replaced with
|
||||||
* @param {?string} optNewName New variable name to merge with. The old
|
* @param {?string} optNewName New variable name to merge with. The old
|
||||||
* variable name in the references being updated should be replaced with this new name.
|
* variable name in the references being updated should be replaced with this new name.
|
||||||
* If this parameter is not provided or is '', no name change occurs.
|
* If this parameter is not provided or is '', no name change occurs.
|
||||||
*/
|
*/
|
||||||
static mergeVariables (idToBeMerged, idToMergeWith, referencesToUpdate, optNewName) {
|
static updateVariableIdentifiers (referencesToUpdate, newId, optNewName) {
|
||||||
referencesToUpdate.map(ref => {
|
referencesToUpdate.map(ref => {
|
||||||
ref.referencingField.id = idToMergeWith;
|
ref.referencingField.id = newId;
|
||||||
if (optNewName) {
|
if (optNewName) {
|
||||||
ref.referencingField.value = optNewName;
|
ref.referencingField.value = optNewName;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue