chore: remove deprecated functionality for v10 (#7077)

* chore: remove deprecated functionality in events files

* chore: remove deprecated items in renderers

* chore: remove deprecated items in core

* chore: remove mixin deprecation

* chore: fix tests after removing deprecations
This commit is contained in:
Rachel Fenichel
2023-05-11 14:30:54 -07:00
committed by GitHub
parent bef5526f1c
commit de904ab128
54 changed files with 24 additions and 1903 deletions

View File

@@ -29,7 +29,6 @@ import {
ToolboxItemSelectJson,
} from './events_toolbox_item_select.js';
import {TrashcanOpen, TrashcanOpenJson} from './events_trashcan_open.js';
import {Ui} from './events_ui.js';
import {UiBase} from './events_ui_base.js';
import {VarBase, VarBaseJson} from './events_var_base.js';
import {VarCreate, VarCreateJson} from './events_var_create.js';
@@ -37,7 +36,7 @@ import {VarDelete, VarDeleteJson} from './events_var_delete.js';
import {VarRename, VarRenameJson} from './events_var_rename.js';
import {ViewportChange, ViewportChangeJson} from './events_viewport.js';
import * as eventUtils from './utils.js';
import {FinishedLoading, FinishedLoadingJson} from './workspace_events.js';
import {FinishedLoading} from './workspace_events.js';
// Events.
export {Abstract};
@@ -70,7 +69,6 @@ export {CommentDelete};
export {CommentMove};
export {CommentMoveJson};
export {FinishedLoading};
export {FinishedLoadingJson};
export {MarkerMove};
export {MarkerMoveJson};
export {Selected};
@@ -81,7 +79,6 @@ export {ToolboxItemSelect};
export {ToolboxItemSelectJson};
export {TrashcanOpen};
export {TrashcanOpenJson};
export {Ui};
export {UiBase};
export {VarBase};
export {VarBaseJson};

View File

@@ -13,7 +13,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.Abstract');
import * as deprecation from '../utils/deprecation.js';
import * as common from '../common.js';
import type {Workspace} from '../workspace.js';
@@ -66,22 +65,6 @@ export abstract class Abstract {
};
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
fromJson(json: AbstractEventJson) {
deprecation.warn(
'Blockly.Events.Abstract.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
this.isBlank = false;
this.group = json['group'] || '';
}
/**
* Deserializes the JSON event.
*

View File

@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.BlockBase');
import type {Block} from '../block.js';
import * as deprecation from '../utils/deprecation.js';
import type {Workspace} from '../workspace.js';
import {
@@ -61,22 +60,6 @@ export class BlockBase extends AbstractEvent {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: BlockBaseJson) {
deprecation.warn(
'Blockly.Events.BlockBase.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.blockId = json['blockId'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -14,7 +14,6 @@ goog.declareModuleId('Blockly.Events.BlockChange');
import type {Block} from '../block.js';
import type {BlockSvg} from '../block_svg.js';
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import * as utilsXml from '../utils/xml.js';
import {Workspace} from '../workspace.js';
@@ -89,25 +88,6 @@ export class BlockChange extends BlockBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: BlockChangeJson) {
deprecation.warn(
'Blockly.Events.BlockChange.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.element = json['element'];
this.name = json['name'];
this.oldValue = json['oldValue'];
this.newValue = json['newValue'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.BlockCreate');
import type {Block} from '../block.js';
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import * as blocks from '../serialization/blocks.js';
import * as utilsXml from '../utils/xml.js';
@@ -92,27 +91,6 @@ export class BlockCreate extends BlockBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: BlockCreateJson) {
deprecation.warn(
'Blockly.Events.BlockCreate.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.xml = utilsXml.textToDom(json['xml']);
this.ids = json['ids'];
this.json = json['json'] as blocks.State;
if (json['recordUndo'] !== undefined) {
this.recordUndo = json['recordUndo'];
}
}
/**
* Deserializes the JSON event.
*

View File

@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.BlockDelete');
import type {Block} from '../block.js';
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import * as blocks from '../serialization/blocks.js';
import * as utilsXml from '../utils/xml.js';
@@ -107,29 +106,6 @@ export class BlockDelete extends BlockBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: BlockDeleteJson) {
deprecation.warn(
'Blockly.Events.BlockDelete.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.oldXml = utilsXml.textToDom(json['oldXml']);
this.ids = json['ids'];
this.wasShadow =
json['wasShadow'] || this.oldXml.tagName.toLowerCase() === 'shadow';
this.oldJson = json['oldJson'];
if (json['recordUndo'] !== undefined) {
this.recordUndo = json['recordUndo'];
}
}
/**
* Deserializes the JSON event.
*

View File

@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.BlockDrag');
import type {Block} from '../block.js';
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {AbstractEventJson} from './events_abstract.js';
import {UiBase} from './events_ui_base.js';
@@ -83,24 +82,6 @@ export class BlockDrag extends UiBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: BlockDragJson) {
deprecation.warn(
'Blockly.Events.BlockDrag.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.isStart = json['isStart'];
this.blockId = json['blockId'];
this.blocks = json['blocks'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -14,7 +14,6 @@ goog.declareModuleId('Blockly.Events.BlockMove');
import type {Block} from '../block.js';
import {ConnectionType} from '../connection_type.js';
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {Coordinate} from '../utils/coordinate.js';
@@ -128,39 +127,6 @@ export class BlockMove extends BlockBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: BlockMoveJson) {
deprecation.warn(
'Blockly.Events.BlockMove.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.oldParentId = json['oldParentId'];
this.oldInputName = json['oldInputName'];
if (json['oldCoordinate']) {
const xy = json['oldCoordinate'].split(',');
this.oldCoordinate = new Coordinate(Number(xy[0]), Number(xy[1]));
}
this.newParentId = json['newParentId'];
this.newInputName = json['newInputName'];
if (json['newCoordinate']) {
const xy = json['newCoordinate'].split(',');
this.newCoordinate = new Coordinate(Number(xy[0]), Number(xy[1]));
}
if (json['reason'] !== undefined) {
this.reason = json['reason'];
}
if (json['recordUndo'] !== undefined) {
this.recordUndo = json['recordUndo'];
}
}
/**
* Deserializes the JSON event.
*

View File

@@ -14,7 +14,6 @@ goog.declareModuleId('Blockly.Events.BubbleOpen');
import type {AbstractEventJson} from './events_abstract.js';
import type {BlockSvg} from '../block_svg.js';
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {UiBase} from './events_ui_base.js';
import * as eventUtils from './utils.js';
@@ -81,24 +80,6 @@ export class BubbleOpen extends UiBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: BubbleOpenJson) {
deprecation.warn(
'Blockly.Events.BubbleOpen.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.isOpen = json['isOpen'];
this.bubbleType = json['bubbleType'];
this.blockId = json['blockId'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -13,7 +13,6 @@ import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.Click');
import type {Block} from '../block.js';
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {AbstractEventJson} from './events_abstract.js';
@@ -77,23 +76,6 @@ export class Click extends UiBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: ClickJson) {
deprecation.warn(
'Blockly.Events.Click.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.targetType = json['targetType'];
this.blockId = json['blockId'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.CommentBase');
import * as deprecation from '../utils/deprecation.js';
import * as utilsXml from '../utils/xml.js';
import type {WorkspaceComment} from '../workspace_comment.js';
import * as Xml from '../xml.js';
@@ -69,22 +68,6 @@ export class CommentBase extends AbstractEvent {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: CommentBaseJson) {
deprecation.warn(
'Blockly.Events.CommentBase.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.commentId = json['commentId'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.CommentChange');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import type {WorkspaceComment} from '../workspace_comment.js';
@@ -80,23 +79,6 @@ export class CommentChange extends CommentBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: CommentChangeJson) {
deprecation.warn(
'Blockly.Events.CommentChange.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.oldContents_ = json['oldContents'];
this.newContents_ = json['newContents'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.CommentCreate');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import type {WorkspaceComment} from '../workspace_comment.js';
import * as utilsXml from '../utils/xml.js';
@@ -63,22 +62,6 @@ export class CommentCreate extends CommentBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: CommentCreateJson) {
deprecation.warn(
'Blockly.Events.CommentCreate.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.xml = utilsXml.textToDom(json['xml']);
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.CommentMove');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {Coordinate} from '../utils/coordinate.js';
import type {WorkspaceComment} from '../workspace_comment.js';
@@ -112,25 +111,6 @@ export class CommentMove extends CommentBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: CommentMoveJson) {
deprecation.warn(
'Blockly.Events.CommentMove.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
let xy = json['oldCoordinate'].split(',');
this.oldCoordinate_ = new Coordinate(Number(xy[0]), Number(xy[1]));
xy = json['newCoordinate'].split(',');
this.newCoordinate_ = new Coordinate(Number(xy[0]), Number(xy[1]));
}
/**
* Deserializes the JSON event.
*

View File

@@ -14,7 +14,6 @@ goog.declareModuleId('Blockly.Events.MarkerMove');
import type {Block} from '../block.js';
import {ASTNode} from '../keyboard_nav/ast_node.js';
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import type {Workspace} from '../workspace.js';
import {AbstractEventJson} from './events_abstract.js';
@@ -99,25 +98,6 @@ export class MarkerMove extends UiBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: MarkerMoveJson) {
deprecation.warn(
'Blockly.Events.MarkerMove.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.isCursor = json['isCursor'];
this.blockId = json['blockId'];
this.oldNode = json['oldNode'];
this.newNode = json['newNode'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.Selected');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {AbstractEventJson} from './events_abstract.js';
@@ -67,23 +66,6 @@ export class Selected extends UiBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: SelectedJson) {
deprecation.warn(
'Blockly.Events.Selected.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.oldElementId = json['oldElementId'];
this.newElementId = json['newElementId'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.ThemeChange');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {AbstractEventJson} from './events_abstract.js';
import {UiBase} from './events_ui_base.js';
@@ -55,22 +54,6 @@ export class ThemeChange extends UiBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: ThemeChangeJson) {
deprecation.warn(
'Blockly.Events.ThemeChange.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.themeName = json['themeName'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.ToolboxItemSelect');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {AbstractEventJson} from './events_abstract.js';
import {UiBase} from './events_ui_base.js';
@@ -61,23 +60,6 @@ export class ToolboxItemSelect extends UiBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: ToolboxItemSelectJson) {
deprecation.warn(
'Blockly.Events.ToolboxItemSelect.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.oldItem = json['oldItem'];
this.newItem = json['newItem'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.TrashcanOpen');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {AbstractEventJson} from './events_abstract.js';
@@ -59,22 +58,6 @@ export class TrashcanOpen extends UiBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: TrashcanOpenJson) {
deprecation.warn(
'Blockly.Events.TrashcanOpen.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.isOpen = json['isOpen'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -1,85 +0,0 @@
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* (Deprecated) Events fired as a result of UI actions in
* Blockly's editor.
*
* @class
*/
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.Ui');
import type {Block} from '../block.js';
import * as registry from '../registry.js';
import {UiBase} from './events_ui_base.js';
import * as eventUtils from './utils.js';
/**
* Class for a UI event.
*
* @deprecated December 2020. Instead use a more specific UI event.
*/
export class Ui extends UiBase {
blockId: AnyDuringMigration;
element: AnyDuringMigration;
oldValue: AnyDuringMigration;
newValue: AnyDuringMigration;
override type = eventUtils.UI;
/**
* @param opt_block The affected block. Null for UI events that do not have
* an associated block. Undefined for a blank event.
* @param opt_element One of 'selected', 'comment', 'mutatorOpen', etc.
* @param opt_oldValue Previous value of element.
* @param opt_newValue New value of element.
*/
constructor(
opt_block?: Block | null,
opt_element?: string,
opt_oldValue?: AnyDuringMigration,
opt_newValue?: AnyDuringMigration
) {
const workspaceId = opt_block ? opt_block.workspace.id : undefined;
super(workspaceId);
this.blockId = opt_block ? opt_block.id : null;
this.element = typeof opt_element === 'undefined' ? '' : opt_element;
this.oldValue = typeof opt_oldValue === 'undefined' ? '' : opt_oldValue;
this.newValue = typeof opt_newValue === 'undefined' ? '' : opt_newValue;
}
/**
* Encode the event as JSON.
*
* @returns JSON representation.
*/
override toJson(): AnyDuringMigration {
const json = super.toJson() as AnyDuringMigration;
json['element'] = this.element;
if (this.newValue !== undefined) {
json['newValue'] = this.newValue;
}
if (this.blockId) {
json['blockId'] = this.blockId;
}
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: AnyDuringMigration) {
super.fromJson(json);
this.element = json['element'];
this.newValue = json['newValue'];
this.blockId = json['blockId'];
}
}
registry.register(registry.Type.EVENT, eventUtils.UI, Ui);

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.VarBase');
import * as deprecation from '../utils/deprecation.js';
import type {VariableModel} from '../variable_model.js';
import {
@@ -59,22 +58,6 @@ export class VarBase extends AbstractEvent {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: VarBaseJson) {
deprecation.warn(
'Blockly.Events.VarBase.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.varId = json['varId'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.VarCreate');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import type {VariableModel} from '../variable_model.js';
@@ -69,23 +68,6 @@ export class VarCreate extends VarBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: VarCreateJson) {
deprecation.warn(
'Blockly.Events.VarCreate.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.varType = json['varType'];
this.varName = json['varName'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -7,7 +7,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.VarDelete');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import type {VariableModel} from '../variable_model.js';
@@ -64,23 +63,6 @@ export class VarDelete extends VarBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: VarDeleteJson) {
deprecation.warn(
'Blockly.Events.VarDelete.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.varType = json['varType'];
this.varName = json['varName'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -7,7 +7,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.VarRename');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import type {VariableModel} from '../variable_model.js';
@@ -67,23 +66,6 @@ export class VarRename extends VarBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: VarRenameJson) {
deprecation.warn(
'Blockly.Events.VarRename.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.oldName = json['oldName'];
this.newName = json['newName'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -12,7 +12,6 @@
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.ViewportChange');
import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js';
import {AbstractEventJson} from './events_abstract.js';
import {UiBase} from './events_ui_base.js';
@@ -110,25 +109,6 @@ export class ViewportChange extends UiBase {
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: ViewportChangeJson) {
deprecation.warn(
'Blockly.Events.Viewport.prototype.fromJson',
'version 9',
'version 10',
'Blockly.Events.fromJson'
);
super.fromJson(json);
this.viewTop = json['viewTop'];
this.viewLeft = json['viewLeft'];
this.scale = json['scale'];
this.oldScale = json['oldScale'];
}
/**
* Deserializes the JSON event.
*

View File

@@ -487,32 +487,7 @@ export function fromJson(
const eventClass = get(json['type']);
if (!eventClass) throw Error('Unknown event type.');
if (eventClassHasStaticFromJson(eventClass)) {
return (eventClass as any).fromJson(json, workspace);
}
// Fallback to the old deserialization method.
const event = new eventClass();
event.fromJson(json);
event.workspaceId = workspace.id;
return event;
}
/**
* Returns true if the given event constructor has /its own/ static fromJson
* method.
*
* Returns false if no static fromJson method exists on the contructor, or if
* the static fromJson method is inheritted.
*/
function eventClassHasStaticFromJson(
eventClass: new (...p: any[]) => Abstract
): boolean {
const untypedEventClass = eventClass as any;
return (
Object.getOwnPropertyDescriptors(untypedEventClass).fromJson &&
typeof untypedEventClass.fromJson === 'function'
);
return (eventClass as any).fromJson(json, workspace);
}
/**

View File

@@ -14,10 +14,7 @@ goog.declareModuleId('Blockly.Events.FinishedLoading');
import * as registry from '../registry.js';
import type {Workspace} from '../workspace.js';
import {
Abstract as AbstractEvent,
AbstractEventJson,
} from './events_abstract.js';
import {Abstract as AbstractEvent} from './events_abstract.js';
import * as eventUtils from './utils.js';
/**
@@ -41,37 +38,6 @@ export class FinishedLoading extends AbstractEvent {
this.workspaceId = opt_workspace.id;
}
/**
* Encode the event as JSON.
*
* @returns JSON representation.
*/
override toJson(): FinishedLoadingJson {
const json = super.toJson() as FinishedLoadingJson;
if (!this.workspaceId) {
throw new Error(
'The workspace ID is undefined. Either pass a workspace to ' +
'the constructor, or call fromJson'
);
}
json['workspaceId'] = this.workspaceId;
return json;
}
/**
* Decode the JSON event.
*
* @param json JSON representation.
*/
override fromJson(json: FinishedLoadingJson) {
super.fromJson(json);
this.workspaceId = json['workspaceId'];
}
}
export interface FinishedLoadingJson extends AbstractEventJson {
workspaceId: string;
}
registry.register(