Files
blockly/core/events/workspace_events.js
Rachel Fenichel b52c65c810 refactor: convert some classes to ES6 classes (#5928)
* refactor: move optional function declarations into the constructor

* refactor: convert options.js to es6 class

* refactor: convert generator.js to es6 class

* refactor: convert workspace_events.js to es6 class

* refactor: convert events_abstract.js to an es6 class

* chore: format

* chore: fix lint

* chore: rebuild

* chore: respond to PR feedback
2022-02-16 13:48:18 -08:00

94 lines
2.2 KiB
JavaScript

/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Class for a finished loading workspace event.
*/
'use strict';
/**
* Class for a finished loading workspace event.
* @class
*/
goog.module('Blockly.Events.FinishedLoading');
const eventUtils = goog.require('Blockly.Events.utils');
const registry = goog.require('Blockly.registry');
const {Abstract: AbstractEvent} = goog.require('Blockly.Events.Abstract');
/* eslint-disable-next-line no-unused-vars */
const {Workspace} = goog.requireType('Blockly.Workspace');
/**
* Class for a finished loading event.
* Used to notify the developer when the workspace has finished loading (i.e
* domToWorkspace).
* Finished loading events do not record undo or redo.
* @extends {AbstractEvent}
*/
class FinishedLoading extends AbstractEvent {
/**
* @param {!Workspace=} opt_workspace The workspace that has finished
* loading. Undefined for a blank event.
* @alias Blockly.Events.FinishedLoading
*/
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;
}
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
toJson() {
const json = {
'type': this.type,
};
if (this.group) {
json['group'] = this.group;
}
if (this.workspaceId) {
json['workspaceId'] = this.workspaceId;
}
return json;
}
/**
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
fromJson(json) {
this.isBlank = false;
this.workspaceId = json['workspaceId'];
this.group = json['group'];
}
}
registry.register(
registry.Type.EVENT, eventUtils.FINISHED_LOADING, FinishedLoading);
exports.FinishedLoading = FinishedLoading;