Files
blockly/core/events/workspace_events.js
Aaron Dodson fbd7c8ab79 Migrate core/events/workspace_events.js to goog.module syntax (#5274)
* Migrate core/events/workspace_events.js to ES6 const/let

* Migrate core/events/workspace_events.js to goog.module

* Migrate core/events/workspace_events.js to named requires

* clang-format core/events/workspace_events.js

* Update build artifact sizes in check_metadata.sh

* Add comment about root cause of build artifact size change

* Migrate core/events/workspace_events.js to ES6 const/let

* Migrate core/events/workspace_events.js to goog.module

* Migrate core/events/workspace_events.js to named requires

* clang-format core/events/workspace_events.js

* Clarify require name for Blockly.Events.Abstract
2021-08-09 12:43:06 -07:00

97 lines
2.4 KiB
JavaScript

/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Class for a finished loading workspace event.
* @author BeksOmega
*/
'use strict';
goog.module('Blockly.Events.FinishedLoading');
goog.module.declareLegacyNamespace();
const Events = goog.require('Blockly.Events');
const EventsAbstract = goog.require('Blockly.Events.Abstract');
/* eslint-disable-next-line no-unused-vars */
const Workspace = goog.requireType('Blockly.Workspace');
const object = goog.require('Blockly.utils.object');
const registry = goog.require('Blockly.registry');
/**
* 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.
* @param {!Workspace=} opt_workspace The workspace that has finished
* loading. Undefined for a blank event.
* @extends {EventsAbstract}
* @constructor
*/
const FinishedLoading = function(opt_workspace) {
/**
* 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 : '';
/**
* 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}
*/
this.group = Events.getGroup();
// Workspace events do not undo or redo.
this.recordUndo = false;
};
object.inherits(FinishedLoading, EventsAbstract);
/**
* Type of this event.
* @type {string}
*/
FinishedLoading.prototype.type = Events.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;
}
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, Events.FINISHED_LOADING, FinishedLoading);
exports = FinishedLoading;