Skip to content

Commit cb47467

Browse files
committed
fix: Remove deprecated calls from block-shareable-procedures
1 parent 50e4b7f commit cb47467

5 files changed

Lines changed: 48 additions & 28 deletions

File tree

plugins/block-shareable-procedures/src/blocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ const procedureDefVarMixin = function () {
257257
* @this {Blockly.Block}
258258
*/
259259
renameVarById: function (oldId, newId) {
260-
const oldVar = this.workspace.getVariableById(oldId);
260+
const oldVar = this.workspace.getVariableMap().getVariableById(oldId);
261261
const model = this.getProcedureModel();
262262
const index = model
263263
.getParameters()
264264
.findIndex((p) => p.getVariableModel() === oldVar);
265265
if (index === -1) return; // Not found.
266-
const newVar = this.workspace.getVariableById(newId);
266+
const newVar = this.workspace.getVariableMap().getVariableById(newId);
267267
const oldParam = model.getParameter(index);
268268
oldParam.setName(newVar.name);
269269
},

plugins/block-shareable-procedures/src/observable_parameter_model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export class ObservableParameterModel
4747
if (name === this.variable.getName()) return this;
4848
const oldName = this.variable.getName();
4949
this.variable =
50-
this.workspace.getVariable(name) ??
51-
this.workspace.createVariable(name, '', id);
50+
this.workspace.getVariableMap().getVariable(name) ??
51+
this.workspace.getVariableMap().createVariable(name, '', id);
5252
triggerProceduresUpdate(this.workspace);
5353
if (this.shouldFireEvents) {
5454
Blockly.Events.fire(

plugins/block-shareable-procedures/test/data_models.mocha.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ suite('Procedure data models', function () {
491491

492492
suite('backing variable to parameters', function () {
493493
test('construction references an existing variable if available', function () {
494-
const variable = this.workspace.createVariable('test1');
494+
const variable = this.workspace.getVariableMap().createVariable('test1');
495495
const param = new ObservableParameterModel(this.workspace, 'test1');
496496

497497
chai.assert.equal(
@@ -505,14 +505,14 @@ suite('Procedure data models', function () {
505505
const param = new ObservableParameterModel(this.workspace, 'test1');
506506

507507
chai.assert.equal(
508-
this.workspace.getVariable('test1'),
508+
this.workspace.getVariableMap().getVariable('test1'),
509509
param.getVariableModel(),
510510
'Expected the parameter model to create a variable',
511511
);
512512
});
513513

514514
test('setName references an existing variable if available', function () {
515-
const variable = this.workspace.createVariable('test2');
515+
const variable = this.workspace.getVariableMap().createVariable('test2');
516516
const param = new ObservableParameterModel(this.workspace, 'test1');
517517

518518
param.setName('test2');
@@ -530,7 +530,7 @@ suite('Procedure data models', function () {
530530
param.setName('test2');
531531

532532
chai.assert.equal(
533-
this.workspace.getVariable('test2'),
533+
this.workspace.getVariableMap().getVariable('test2'),
534534
param.getVariableModel(),
535535
'Expected the parameter model to create a variable',
536536
);

plugins/block-shareable-procedures/test/procedure_blocks.mocha.js

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ suite('Procedures', function () {
4747
this.eventSpy = this.sandbox.spy();
4848
this.workspace.addChangeListener(this.eventSpy);
4949

50-
this.workspace.createVariable('preCreatedVar', '', 'preCreatedVarId');
51-
this.workspace.createVariable(
52-
'preCreatedTypedVar',
53-
'type',
54-
'preCreatedTypedVarId',
55-
);
50+
this.workspace
51+
.getVariableMap()
52+
.createVariable('preCreatedVar', '', 'preCreatedVarId');
53+
this.workspace
54+
.getVariableMap()
55+
.createVariable('preCreatedTypedVar', 'type', 'preCreatedTypedVarId');
5656

5757
Blockly.defineBlocksWithJsonArray([
5858
{
@@ -869,7 +869,7 @@ suite('Procedures', function () {
869869
defBlock.compose(containerBlock);
870870

871871
assert.isNotNull(
872-
this.workspace.getVariable('param1', ''),
872+
this.workspace.getVariableMap().getVariable('param1', ''),
873873
'Expected the old variable to continue to exist',
874874
);
875875
});
@@ -890,8 +890,10 @@ suite('Procedures', function () {
890890
.connection.connect(paramBlock.previousConnection);
891891
defBlock.compose(containerBlock);
892892

893-
const variable = this.workspace.getVariable('param1', '');
894-
this.workspace.renameVariableById(variable.getId(), 'new name');
893+
const variable = this.workspace
894+
.getVariableMap()
895+
.getVariable('param1', '');
896+
this.workspace.getVariableMap().renameVariable(variable, 'new name');
895897

896898
assert.isNotNull(
897899
defBlock.getField('PARAMS'),
@@ -922,8 +924,10 @@ suite('Procedures', function () {
922924
.connection.connect(paramBlock.previousConnection);
923925
defBlock.compose(containerBlock);
924926

925-
const variable = this.workspace.getVariable('param1', '');
926-
this.workspace.renameVariableById(variable.getId(), 'new name');
927+
const variable = this.workspace
928+
.getVariableMap()
929+
.getVariable('param1', '');
930+
this.workspace.getVariableMap().renameVariable(variable, 'new name');
927931

928932
assert.equal(
929933
paramBlock.getFieldValue('NAME'),
@@ -950,8 +954,10 @@ suite('Procedures', function () {
950954
.connection.connect(paramBlock.previousConnection);
951955
defBlock.compose(containerBlock);
952956

953-
const variable = this.workspace.getVariable('param1', '');
954-
this.workspace.renameVariableById(variable.getId(), 'new name');
957+
const variable = this.workspace
958+
.getVariableMap()
959+
.getVariable('param1', '');
960+
this.workspace.getVariableMap().renameVariable(variable, 'new name');
955961

956962
assert.isNotNull(
957963
callBlock.getInput('ARG0'),
@@ -981,8 +987,12 @@ suite('Procedures', function () {
981987
.connection.connect(paramBlock.previousConnection);
982988
defBlock.compose(containerBlock);
983989

984-
const variable = this.workspace.getVariable('param1', '');
985-
this.workspace.renameVariableById(variable.getId(), 'preCreatedVar');
990+
const variable = this.workspace
991+
.getVariableMap()
992+
.getVariable('param1', '');
993+
this.workspace
994+
.getVariableMap()
995+
.renameVariable(variable, 'preCreatedVar');
986996

987997
assert.isNotNull(
988998
defBlock.getField('PARAMS'),
@@ -1013,8 +1023,12 @@ suite('Procedures', function () {
10131023
.connection.connect(paramBlock.previousConnection);
10141024
defBlock.compose(containerBlock);
10151025

1016-
const variable = this.workspace.getVariable('param1', '');
1017-
this.workspace.renameVariableById(variable.getId(), 'preCreatedVar');
1026+
const variable = this.workspace
1027+
.getVariableMap()
1028+
.getVariable('param1', '');
1029+
this.workspace
1030+
.getVariableMap()
1031+
.renameVariable(variable, 'preCreatedVar');
10181032

10191033
assert.equal(
10201034
paramBlock.getFieldValue('NAME'),
@@ -1041,8 +1055,12 @@ suite('Procedures', function () {
10411055
.connection.connect(paramBlock.previousConnection);
10421056
defBlock.compose(containerBlock);
10431057

1044-
const variable = this.workspace.getVariable('param1', '');
1045-
this.workspace.renameVariableById(variable.getId(), 'preCreatedVar');
1058+
const variable = this.workspace
1059+
.getVariableMap()
1060+
.getVariable('param1', '');
1061+
this.workspace
1062+
.getVariableMap()
1063+
.renameVariable(variable, 'preCreatedVar');
10461064

10471065
assert.isNotNull(
10481066
callBlock.getInput('ARG0'),

plugins/block-shareable-procedures/test/procedure_test_helpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export function createGenUidStubWithReturns(returnIds) {
4242
export function assertBlockVarModels(block, varIds) {
4343
const expectedVarModels = [];
4444
for (let i = 0; i < varIds.length; i++) {
45-
expectedVarModels.push(block.workspace.getVariableById(varIds[i]));
45+
expectedVarModels.push(
46+
block.workspace.getVariableMap().getVariableById(varIds[i]),
47+
);
4648
}
4749
assert.sameDeepOrderedMembers(block.getVarModels(), expectedVarModels);
4850
}

0 commit comments

Comments
 (0)