Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert some classes to ES6 classes #5928

Merged
102 changes: 48 additions & 54 deletions core/events/workspace_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
goog.module('Blockly.Events.FinishedLoading');

const eventUtils = goog.require('Blockly.Events.utils');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');
const {Abstract} = goog.require('Blockly.Events.Abstract');
/* eslint-disable-next-line no-unused-vars */
Expand All @@ -28,70 +27,65 @@ const {Workspace} = goog.requireType('Blockly.Workspace');
* Used to notify the developer when the workspace has finished loading (i.e
* domToWorkspace).
* Finished loading events do not record undo or redo.
* @param {!Workspace=} opt_workspace The workspace that has finished
* loading. Undefined for a blank event.
* @extends {Abstract}
* @constructor
* @alias Blockly.Events.FinishedLoading
*/
const FinishedLoading = function(opt_workspace) {
class FinishedLoading extends Abstract {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: it might be helpful for readability if the superclass were imported as AbstractEvent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/**
* Whether or not the event is blank (to be populated by fromJson).
* @type {boolean}
* @param {!Workspace=} opt_workspace The workspace that has finished
* loading. Undefined for a blank event.
* @alias Blockly.Events.FinishedLoading
*/
this.isBlank = typeof opt_workspace === 'undefined';
constructor(opt_workspace) {
super();
/**
* Whether or not the event is blank (to be populated by fromJson).
* @type {boolean}
*/
this.isBlank = typeof opt_workspace === 'undefined';

/**
* The workspace identifier for this event.
* @type {string}
*/
this.workspaceId = opt_workspace ? opt_workspace.id : '';

// Workspace events do not undo or redo.
this.recordUndo = false;

/**
* Type of this event.
* @type {string}
*/
this.type = eventUtils.FINISHED_LOADING;
}

/**
* The workspace identifier for this event.
* @type {string}
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
this.workspaceId = opt_workspace ? opt_workspace.id : '';
toJson() {
const json = {
'type': this.type,
};
if (this.group) {
json['group'] = this.group;
}
if (this.workspaceId) {
json['workspaceId'] = this.workspaceId;
}
return json;
}

/**
* The event group ID for the group this event belongs to. Groups define
* events that should be treated as an single action from the user's
* perspective, and should be undone together.
* @type {string}
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
this.group = eventUtils.getGroup();

// Workspace events do not undo or redo.
this.recordUndo = false;
};
object.inherits(FinishedLoading, Abstract);

/**
* Type of this event.
* @type {string}
*/
FinishedLoading.prototype.type = eventUtils.FINISHED_LOADING;

/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
FinishedLoading.prototype.toJson = function() {
const json = {
'type': this.type,
};
if (this.group) {
json['group'] = this.group;
fromJson(json) {
this.isBlank = false;
this.workspaceId = json['workspaceId'];
this.group = json['group'];
}
if (this.workspaceId) {
json['workspaceId'] = this.workspaceId;
}
return json;
};

/**
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
FinishedLoading.prototype.fromJson = function(json) {
this.isBlank = false;
this.workspaceId = json['workspaceId'];
this.group = json['group'];
};
}

registry.register(
registry.Type.EVENT, eventUtils.FINISHED_LOADING, FinishedLoading);
Expand Down