From fbd7c8ab79459cee6a629dc7ade9aed993c928f4 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 9 Aug 2021 12:43:06 -0700 Subject: [PATCH] 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 --- core/events/workspace_events.js | 41 +++++++++++++++++---------------- tests/deps.js | 2 +- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/core/events/workspace_events.js b/core/events/workspace_events.js index bb22097a0..df832602e 100644 --- a/core/events/workspace_events.js +++ b/core/events/workspace_events.js @@ -10,14 +10,15 @@ */ 'use strict'; -goog.provide('Blockly.Events.FinishedLoading'); +goog.module('Blockly.Events.FinishedLoading'); +goog.module.declareLegacyNamespace(); -goog.require('Blockly.Events'); -goog.require('Blockly.Events.Abstract'); -goog.require('Blockly.registry'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Workspace'); +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'); /** @@ -25,13 +26,12 @@ 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 {!Blockly.Workspace=} opt_workspace The workspace that has finished + * @param {!Workspace=} opt_workspace The workspace that has finished * loading. Undefined for a blank event. - * @extends {Blockly.Events.Abstract} + * @extends {EventsAbstract} * @constructor */ -Blockly.Events.FinishedLoading = function(opt_workspace) { - +const FinishedLoading = function(opt_workspace) { /** * Whether or not the event is blank (to be populated by fromJson). * @type {boolean} @@ -50,26 +50,25 @@ Blockly.Events.FinishedLoading = function(opt_workspace) { * perspective, and should be undone together. * @type {string} */ - this.group = Blockly.Events.getGroup(); + this.group = Events.getGroup(); // Workspace events do not undo or redo. this.recordUndo = false; }; -Blockly.utils.object.inherits(Blockly.Events.FinishedLoading, - Blockly.Events.Abstract); +object.inherits(FinishedLoading, EventsAbstract); /** * Type of this event. * @type {string} */ -Blockly.Events.FinishedLoading.prototype.type = Blockly.Events.FINISHED_LOADING; +FinishedLoading.prototype.type = Events.FINISHED_LOADING; /** * Encode the event as JSON. * @return {!Object} JSON representation. */ -Blockly.Events.FinishedLoading.prototype.toJson = function() { - var json = { +FinishedLoading.prototype.toJson = function() { + const json = { 'type': this.type, }; if (this.group) { @@ -85,11 +84,13 @@ Blockly.Events.FinishedLoading.prototype.toJson = function() { * Decode the JSON event. * @param {!Object} json JSON representation. */ -Blockly.Events.FinishedLoading.prototype.fromJson = function(json) { +FinishedLoading.prototype.fromJson = function(json) { this.isBlank = false; this.workspaceId = json['workspaceId']; this.group = json['group']; }; -Blockly.registry.register(Blockly.registry.Type.EVENT, - Blockly.Events.FINISHED_LOADING, Blockly.Events.FinishedLoading); +registry.register( + registry.Type.EVENT, Events.FINISHED_LOADING, FinishedLoading); + +exports = FinishedLoading; diff --git a/tests/deps.js b/tests/deps.js index d979a3cbe..9a5b768a6 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -48,7 +48,7 @@ goog.addDependency('../../core/events/events_trashcan_open.js', ['Blockly.Events goog.addDependency('../../core/events/events_viewport.js', ['Blockly.Events.ViewportChange'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/ui_events.js', ['Blockly.Events.Ui', 'Blockly.Events.UiBase'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object']); goog.addDependency('../../core/events/variable_events.js', ['Blockly.Events.VarBase', 'Blockly.Events.VarCreate', 'Blockly.Events.VarDelete', 'Blockly.Events.VarRename'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object']); -goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es5'}); +goog.addDependency('../../core/events/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/events/ws_comment_events.js', ['Blockly.Events.CommentBase', 'Blockly.Events.CommentChange', 'Blockly.Events.CommentCreate', 'Blockly.Events.CommentDelete', 'Blockly.Events.CommentMove'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.Xml', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.object', 'Blockly.utils.xml']); goog.addDependency('../../core/extensions.js', ['Blockly.Extensions'], ['Blockly.utils'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/field.js', ['Blockly.Field'], ['Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Gesture', 'Blockly.IASTNodeLocationSvg', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.IKeyboardAccessible', 'Blockly.IRegistrable', 'Blockly.MarkerManager', 'Blockly.Tooltip', 'Blockly.WidgetDiv', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Rect', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.style', 'Blockly.utils.userAgent'], {'lang': 'es6', 'module': 'goog'});