Skip to content

Commit 556ee39

Browse files
authored
fix!: remove deprecated setEnabled and backwards event filtering (#9039)
1 parent 14e1ef6 commit 556ee39

File tree

4 files changed

+12
-110
lines changed

4 files changed

+12
-110
lines changed

core/block.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import * as registry from './registry.js';
5050
import * as Tooltip from './tooltip.js';
5151
import * as arrayUtils from './utils/array.js';
5252
import {Coordinate} from './utils/coordinate.js';
53-
import * as deprecation from './utils/deprecation.js';
5453
import * as idGenerator from './utils/idgenerator.js';
5554
import * as parsing from './utils/parsing.js';
5655
import {Size} from './utils/size.js';
@@ -1410,47 +1409,6 @@ export class Block {
14101409
return this.disabledReasons.size === 0;
14111410
}
14121411

1413-
/** @deprecated v11 - Get or sets whether the block is manually disabled. */
1414-
private get disabled(): boolean {
1415-
deprecation.warn(
1416-
'disabled',
1417-
'v11',
1418-
'v12',
1419-
'the isEnabled or hasDisabledReason methods of Block',
1420-
);
1421-
return this.hasDisabledReason(constants.MANUALLY_DISABLED);
1422-
}
1423-
1424-
private set disabled(value: boolean) {
1425-
deprecation.warn(
1426-
'disabled',
1427-
'v11',
1428-
'v12',
1429-
'the setDisabledReason method of Block',
1430-
);
1431-
this.setDisabledReason(value, constants.MANUALLY_DISABLED);
1432-
}
1433-
1434-
/**
1435-
* @deprecated v11 - Set whether the block is manually enabled or disabled.
1436-
* The user can toggle whether a block is disabled from a context menu
1437-
* option. A block may still be disabled for other reasons even if the user
1438-
* attempts to manually enable it, such as when the block is in an invalid
1439-
* location. This method is deprecated and setDisabledReason should be used
1440-
* instead.
1441-
*
1442-
* @param enabled True if enabled.
1443-
*/
1444-
setEnabled(enabled: boolean) {
1445-
deprecation.warn(
1446-
'setEnabled',
1447-
'v11',
1448-
'v12',
1449-
'the setDisabledReason method of Block',
1450-
);
1451-
this.setDisabledReason(!enabled, constants.MANUALLY_DISABLED);
1452-
}
1453-
14541412
/**
14551413
* Add or remove a reason why the block might be disabled. If a block has
14561414
* any reasons to be disabled, then the block itself will be considered

core/block_svg.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import * as blocks from './serialization/blocks.js';
5757
import type {BlockStyle} from './theme.js';
5858
import * as Tooltip from './tooltip.js';
5959
import {Coordinate} from './utils/coordinate.js';
60-
import * as deprecation from './utils/deprecation.js';
6160
import * as dom from './utils/dom.js';
6261
import {Rect} from './utils/rect.js';
6362
import {Svg} from './utils/svg.js';
@@ -1078,32 +1077,6 @@ export class BlockSvg
10781077
return removed;
10791078
}
10801079

1081-
/**
1082-
* Set whether the block is manually enabled or disabled.
1083-
*
1084-
* The user can toggle whether a block is disabled from a context menu
1085-
* option. A block may still be disabled for other reasons even if the user
1086-
* attempts to manually enable it, such as when the block is in an invalid
1087-
* location. This method is deprecated and setDisabledReason should be used
1088-
* instead.
1089-
*
1090-
* @deprecated v11: use setDisabledReason.
1091-
* @param enabled True if enabled.
1092-
*/
1093-
override setEnabled(enabled: boolean) {
1094-
deprecation.warn(
1095-
'setEnabled',
1096-
'v11',
1097-
'v12',
1098-
'the setDisabledReason method of BlockSvg',
1099-
);
1100-
const wasEnabled = this.isEnabled();
1101-
super.setEnabled(enabled);
1102-
if (this.isEnabled() !== wasEnabled && !this.getInheritedDisabled()) {
1103-
this.updateDisabled();
1104-
}
1105-
}
1106-
11071080
/**
11081081
* Add or remove a reason why the block might be disabled. If a block has
11091082
* any reasons to be disabled, then the block itself will be considered

core/events/utils.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import type {Block} from '../block.js';
1010
import * as common from '../common.js';
1111
import * as registry from '../registry.js';
12-
import * as deprecation from '../utils/deprecation.js';
1312
import * as idGenerator from '../utils/idgenerator.js';
1413
import type {Workspace} from '../workspace.js';
1514
import type {WorkspaceSvg} from '../workspace_svg.js';
@@ -124,7 +123,7 @@ function fireInternal(event: Abstract) {
124123

125124
/** Dispatch all queued events. */
126125
function fireNow() {
127-
const queue = filter(FIRE_QUEUE, true);
126+
const queue = filter(FIRE_QUEUE);
128127
FIRE_QUEUE.length = 0;
129128
for (const event of queue) {
130129
if (!event.workspaceId) continue;
@@ -227,18 +226,9 @@ function enqueueEvent(event: Abstract) {
227226
* cause them to be reordered.
228227
*
229228
* @param queue Array of events.
230-
* @param forward True if forward (redo), false if backward (undo).
231-
* This parameter is deprecated: true is now the default and
232-
* calling filter with it set to false will in future not be
233-
* supported.
234229
* @returns Array of filtered events.
235230
*/
236-
export function filter(queue: Abstract[], forward = true): Abstract[] {
237-
if (!forward) {
238-
deprecation.warn('filter(queue, /*forward=*/false)', 'v11.2', 'v12');
239-
// Undo was merged in reverse order.
240-
queue = queue.slice().reverse(); // Copy before reversing in place.
241-
}
231+
export function filter(queue: Abstract[]): Abstract[] {
242232
const mergedQueue: Abstract[] = [];
243233
// Merge duplicates.
244234
for (const event of queue) {
@@ -290,10 +280,6 @@ export function filter(queue: Abstract[], forward = true): Abstract[] {
290280
}
291281
// Filter out any events that have become null due to merging.
292282
queue = mergedQueue.filter((e) => !e.isNull());
293-
if (!forward) {
294-
// Restore undo order.
295-
queue.reverse();
296-
}
297283
return queue;
298284
}
299285

tests/mocha/event_test.js

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ suite('Events', function () {
12221222
new Blockly.Events.BlockChange(block, 'field', 'VAR', 'id1', 'id2'),
12231223
new Blockly.Events.Click(block),
12241224
];
1225-
const filteredEvents = eventUtils.filter(events, true);
1225+
const filteredEvents = eventUtils.filter(events);
12261226
assert.equal(filteredEvents.length, 4); // no event should have been removed.
12271227
// test that the order hasn't changed
12281228
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
@@ -1240,7 +1240,7 @@ suite('Events', function () {
12401240
new Blockly.Events.BlockCreate(block2),
12411241
new Blockly.Events.BlockMove(block2),
12421242
];
1243-
const filteredEvents = eventUtils.filter(events, true);
1243+
const filteredEvents = eventUtils.filter(events);
12441244
assert.equal(filteredEvents.length, 4); // no event should have been removed.
12451245
});
12461246

@@ -1250,7 +1250,7 @@ suite('Events', function () {
12501250
addMoveEvent(events, block, 1, 1);
12511251
addMoveEvent(events, block, 2, 2);
12521252
addMoveEvent(events, block, 3, 3);
1253-
const filteredEvents = eventUtils.filter(events, true);
1253+
const filteredEvents = eventUtils.filter(events);
12541254
assert.equal(filteredEvents.length, 2); // duplicate moves should have been removed.
12551255
// test that the order hasn't changed
12561256
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
@@ -1259,27 +1259,12 @@ suite('Events', function () {
12591259
assert.equal(filteredEvents[1].newCoordinate.y, 3);
12601260
});
12611261

1262-
test('Backward', function () {
1263-
const block = this.workspace.newBlock('field_variable_test_block', '1');
1264-
const events = [new Blockly.Events.BlockCreate(block)];
1265-
addMoveEvent(events, block, 1, 1);
1266-
addMoveEvent(events, block, 2, 2);
1267-
addMoveEvent(events, block, 3, 3);
1268-
const filteredEvents = eventUtils.filter(events, false);
1269-
assert.equal(filteredEvents.length, 2); // duplicate event should have been removed.
1270-
// test that the order hasn't changed
1271-
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
1272-
assert.isTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
1273-
assert.equal(filteredEvents[1].newCoordinate.x, 1);
1274-
assert.equal(filteredEvents[1].newCoordinate.y, 1);
1275-
});
1276-
12771262
test('Merge block move events', function () {
12781263
const block = this.workspace.newBlock('field_variable_test_block', '1');
12791264
const events = [];
12801265
addMoveEvent(events, block, 0, 0);
12811266
addMoveEvent(events, block, 1, 1);
1282-
const filteredEvents = eventUtils.filter(events, true);
1267+
const filteredEvents = eventUtils.filter(events);
12831268
assert.equal(filteredEvents.length, 1); // second move event merged into first
12841269
assert.equal(filteredEvents[0].newCoordinate.x, 1);
12851270
assert.equal(filteredEvents[0].newCoordinate.y, 1);
@@ -1297,7 +1282,7 @@ suite('Events', function () {
12971282
'item2',
12981283
),
12991284
];
1300-
const filteredEvents = eventUtils.filter(events, true);
1285+
const filteredEvents = eventUtils.filter(events);
13011286
assert.equal(filteredEvents.length, 1); // second change event merged into first
13021287
assert.equal(filteredEvents[0].oldValue, 'item');
13031288
assert.equal(filteredEvents[0].newValue, 'item2');
@@ -1308,7 +1293,7 @@ suite('Events', function () {
13081293
new Blockly.Events.ViewportChange(1, 2, 3, this.workspace, 4),
13091294
new Blockly.Events.ViewportChange(5, 6, 7, this.workspace, 8),
13101295
];
1311-
const filteredEvents = eventUtils.filter(events, true);
1296+
const filteredEvents = eventUtils.filter(events);
13121297
assert.equal(filteredEvents.length, 1); // second change event merged into first
13131298
assert.equal(filteredEvents[0].viewTop, 5);
13141299
assert.equal(filteredEvents[0].viewLeft, 6);
@@ -1328,7 +1313,7 @@ suite('Events', function () {
13281313
new Blockly.Events.BubbleOpen(block3, true, 'warning'),
13291314
new Blockly.Events.Click(block3),
13301315
];
1331-
const filteredEvents = eventUtils.filter(events, true);
1316+
const filteredEvents = eventUtils.filter(events);
13321317
// click event merged into corresponding *Open event
13331318
assert.equal(filteredEvents.length, 3);
13341319
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.BubbleOpen);
@@ -1347,7 +1332,7 @@ suite('Events', function () {
13471332
new Blockly.Events.Click(block),
13481333
new Blockly.Events.BlockDrag(block, true),
13491334
];
1350-
const filteredEvents = eventUtils.filter(events, true);
1335+
const filteredEvents = eventUtils.filter(events);
13511336
// click and stackclick should both exist
13521337
assert.equal(filteredEvents.length, 2);
13531338
assert.isTrue(filteredEvents[0] instanceof Blockly.Events.Click);
@@ -1367,7 +1352,7 @@ suite('Events', function () {
13671352
const events = [];
13681353
addMoveEventParent(events, block, null);
13691354
addMoveEventParent(events, block, null);
1370-
const filteredEvents = eventUtils.filter(events, true);
1355+
const filteredEvents = eventUtils.filter(events);
13711356
// The two events should be merged, but because nothing has changed
13721357
// they will be filtered out.
13731358
assert.equal(filteredEvents.length, 0);
@@ -1388,7 +1373,7 @@ suite('Events', function () {
13881373
events.push(new Blockly.Events.BlockDelete(block2));
13891374
addMoveEvent(events, block1, 2, 2);
13901375

1391-
const filteredEvents = eventUtils.filter(events, true);
1376+
const filteredEvents = eventUtils.filter(events);
13921377
// Nothing should have merged.
13931378
assert.equal(filteredEvents.length, 4);
13941379
// test that the order hasn't changed

0 commit comments

Comments
 (0)