mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
Migrate core/events/block_events.js to goog.module
This commit is contained in:
@@ -10,9 +10,9 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.Events.VarBase');
|
||||
goog.module('Blockly.Events.VarBase');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Events.Abstract');
|
||||
goog.require('Blockly.utils.object');
|
||||
|
||||
@@ -26,8 +26,8 @@ goog.requireType('Blockly.VariableModel');
|
||||
* @extends {Blockly.Events.Abstract}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.Events.VarBase = function(opt_variable) {
|
||||
Blockly.Events.VarBase.superClass_.constructor.call(this);
|
||||
const VarBase = function(opt_variable) {
|
||||
VarBase.superClass_.constructor.call(this);
|
||||
this.isBlank = typeof opt_variable == 'undefined';
|
||||
|
||||
/**
|
||||
@@ -42,14 +42,14 @@ Blockly.Events.VarBase = function(opt_variable) {
|
||||
*/
|
||||
this.workspaceId = this.isBlank ? '' : opt_variable.workspace.id;
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.Events.VarBase, Blockly.Events.Abstract);
|
||||
Blockly.utils.object.inherits(VarBase, Blockly.Events.Abstract);
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
* @return {!Object} JSON representation.
|
||||
*/
|
||||
Blockly.Events.VarBase.prototype.toJson = function() {
|
||||
const json = Blockly.Events.VarBase.superClass_.toJson.call(this);
|
||||
VarBase.prototype.toJson = function() {
|
||||
const json = VarBase.superClass_.toJson.call(this);
|
||||
json['varId'] = this.varId;
|
||||
return json;
|
||||
};
|
||||
@@ -58,7 +58,9 @@ Blockly.Events.VarBase.prototype.toJson = function() {
|
||||
* Decode the JSON event.
|
||||
* @param {!Object} json JSON representation.
|
||||
*/
|
||||
Blockly.Events.VarBase.prototype.fromJson = function(json) {
|
||||
Blockly.Events.VarBase.superClass_.toJson.call(this);
|
||||
VarBase.prototype.fromJson = function(json) {
|
||||
VarBase.superClass_.toJson.call(this);
|
||||
this.varId = json['varId'];
|
||||
};
|
||||
|
||||
exports = VarBase;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.Events.VarCreate');
|
||||
goog.module('Blockly.Events.VarCreate');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Events.VarBase');
|
||||
@@ -27,8 +28,8 @@ goog.requireType('Blockly.VariableModel');
|
||||
* @extends {Blockly.Events.VarBase}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.Events.VarCreate = function(opt_variable) {
|
||||
Blockly.Events.VarCreate.superClass_.constructor.call(this, opt_variable);
|
||||
const VarCreate = function(opt_variable) {
|
||||
VarCreate.superClass_.constructor.call(this, opt_variable);
|
||||
if (!opt_variable) {
|
||||
return; // Blank event to be populated by fromJson.
|
||||
}
|
||||
@@ -36,20 +37,20 @@ Blockly.Events.VarCreate = function(opt_variable) {
|
||||
this.varType = opt_variable.type;
|
||||
this.varName = opt_variable.name;
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.Events.VarCreate, Blockly.Events.VarBase);
|
||||
Blockly.utils.object.inherits(VarCreate, Blockly.Events.VarBase);
|
||||
|
||||
/**
|
||||
* Type of this event.
|
||||
* @type {string}
|
||||
*/
|
||||
Blockly.Events.VarCreate.prototype.type = Blockly.Events.VAR_CREATE;
|
||||
VarCreate.prototype.type = Blockly.Events.VAR_CREATE;
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
* @return {!Object} JSON representation.
|
||||
*/
|
||||
Blockly.Events.VarCreate.prototype.toJson = function() {
|
||||
const json = Blockly.Events.VarCreate.superClass_.toJson.call(this);
|
||||
VarCreate.prototype.toJson = function() {
|
||||
const json = VarCreate.superClass_.toJson.call(this);
|
||||
json['varType'] = this.varType;
|
||||
json['varName'] = this.varName;
|
||||
return json;
|
||||
@@ -59,8 +60,8 @@ Blockly.Events.VarCreate.prototype.toJson = function() {
|
||||
* Decode the JSON event.
|
||||
* @param {!Object} json JSON representation.
|
||||
*/
|
||||
Blockly.Events.VarCreate.prototype.fromJson = function(json) {
|
||||
Blockly.Events.VarCreate.superClass_.fromJson.call(this, json);
|
||||
VarCreate.prototype.fromJson = function(json) {
|
||||
VarCreate.superClass_.fromJson.call(this, json);
|
||||
this.varType = json['varType'];
|
||||
this.varName = json['varName'];
|
||||
};
|
||||
@@ -69,7 +70,7 @@ Blockly.Events.VarCreate.prototype.fromJson = function(json) {
|
||||
* Run a variable creation event.
|
||||
* @param {boolean} forward True if run forward, false if run backward (undo).
|
||||
*/
|
||||
Blockly.Events.VarCreate.prototype.run = function(forward) {
|
||||
VarCreate.prototype.run = function(forward) {
|
||||
const workspace = this.getEventWorkspace_();
|
||||
if (forward) {
|
||||
workspace.createVariable(this.varName, this.varType, this.varId);
|
||||
@@ -79,4 +80,6 @@ Blockly.Events.VarCreate.prototype.run = function(forward) {
|
||||
};
|
||||
|
||||
Blockly.registry.register(Blockly.registry.Type.EVENT,
|
||||
Blockly.Events.VAR_CREATE, Blockly.Events.VarCreate);
|
||||
Blockly.Events.VAR_CREATE, VarCreate);
|
||||
|
||||
exports = VarCreate;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.Events.VarDelete');
|
||||
goog.module('Blockly.Events.VarDelete');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Events.VarBase');
|
||||
@@ -27,8 +28,8 @@ goog.requireType('Blockly.VariableModel');
|
||||
* @extends {Blockly.Events.VarBase}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.Events.VarDelete = function(opt_variable) {
|
||||
Blockly.Events.VarDelete.superClass_.constructor.call(this, opt_variable);
|
||||
const VarDelete = function(opt_variable) {
|
||||
VarDelete.superClass_.constructor.call(this, opt_variable);
|
||||
if (!opt_variable) {
|
||||
return; // Blank event to be populated by fromJson.
|
||||
}
|
||||
@@ -36,20 +37,20 @@ Blockly.Events.VarDelete = function(opt_variable) {
|
||||
this.varType = opt_variable.type;
|
||||
this.varName = opt_variable.name;
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.Events.VarDelete, Blockly.Events.VarBase);
|
||||
Blockly.utils.object.inherits(VarDelete, Blockly.Events.VarBase);
|
||||
|
||||
/**
|
||||
* Type of this event.
|
||||
* @type {string}
|
||||
*/
|
||||
Blockly.Events.VarDelete.prototype.type = Blockly.Events.VAR_DELETE;
|
||||
VarDelete.prototype.type = Blockly.Events.VAR_DELETE;
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
* @return {!Object} JSON representation.
|
||||
*/
|
||||
Blockly.Events.VarDelete.prototype.toJson = function() {
|
||||
const json = Blockly.Events.VarDelete.superClass_.toJson.call(this);
|
||||
VarDelete.prototype.toJson = function() {
|
||||
const json = VarDelete.superClass_.toJson.call(this);
|
||||
json['varType'] = this.varType;
|
||||
json['varName'] = this.varName;
|
||||
return json;
|
||||
@@ -59,8 +60,8 @@ Blockly.Events.VarDelete.prototype.toJson = function() {
|
||||
* Decode the JSON event.
|
||||
* @param {!Object} json JSON representation.
|
||||
*/
|
||||
Blockly.Events.VarDelete.prototype.fromJson = function(json) {
|
||||
Blockly.Events.VarDelete.superClass_.fromJson.call(this, json);
|
||||
VarDelete.prototype.fromJson = function(json) {
|
||||
VarDelete.superClass_.fromJson.call(this, json);
|
||||
this.varType = json['varType'];
|
||||
this.varName = json['varName'];
|
||||
};
|
||||
@@ -69,7 +70,7 @@ Blockly.Events.VarDelete.prototype.fromJson = function(json) {
|
||||
* Run a variable deletion event.
|
||||
* @param {boolean} forward True if run forward, false if run backward (undo).
|
||||
*/
|
||||
Blockly.Events.VarDelete.prototype.run = function(forward) {
|
||||
VarDelete.prototype.run = function(forward) {
|
||||
const workspace = this.getEventWorkspace_();
|
||||
if (forward) {
|
||||
workspace.deleteVariableById(this.varId);
|
||||
@@ -79,4 +80,6 @@ Blockly.Events.VarDelete.prototype.run = function(forward) {
|
||||
};
|
||||
|
||||
Blockly.registry.register(Blockly.registry.Type.EVENT,
|
||||
Blockly.Events.VAR_DELETE, Blockly.Events.VarDelete);
|
||||
Blockly.Events.VAR_DELETE, VarDelete);
|
||||
|
||||
exports = VarDelete;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.Events.VarRename');
|
||||
goog.module('Blockly.Events.VarRename');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
goog.require('Blockly.Events');
|
||||
goog.require('Blockly.Events.VarBase');
|
||||
@@ -28,8 +29,8 @@ goog.requireType('Blockly.VariableModel');
|
||||
* @extends {Blockly.Events.VarBase}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.Events.VarRename = function(opt_variable, newName) {
|
||||
Blockly.Events.VarRename.superClass_.constructor.call(this, opt_variable);
|
||||
const VarRename = function(opt_variable, newName) {
|
||||
VarRename.superClass_.constructor.call(this, opt_variable);
|
||||
if (!opt_variable) {
|
||||
return; // Blank event to be populated by fromJson.
|
||||
}
|
||||
@@ -37,20 +38,20 @@ Blockly.Events.VarRename = function(opt_variable, newName) {
|
||||
this.oldName = opt_variable.name;
|
||||
this.newName = typeof newName == 'undefined' ? '' : newName;
|
||||
};
|
||||
Blockly.utils.object.inherits(Blockly.Events.VarRename, Blockly.Events.VarBase);
|
||||
Blockly.utils.object.inherits(VarRename, Blockly.Events.VarBase);
|
||||
|
||||
/**
|
||||
* Type of this event.
|
||||
* @type {string}
|
||||
*/
|
||||
Blockly.Events.VarRename.prototype.type = Blockly.Events.VAR_RENAME;
|
||||
VarRename.prototype.type = Blockly.Events.VAR_RENAME;
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
* @return {!Object} JSON representation.
|
||||
*/
|
||||
Blockly.Events.VarRename.prototype.toJson = function() {
|
||||
const json = Blockly.Events.VarRename.superClass_.toJson.call(this);
|
||||
VarRename.prototype.toJson = function() {
|
||||
const json = VarRename.superClass_.toJson.call(this);
|
||||
json['oldName'] = this.oldName;
|
||||
json['newName'] = this.newName;
|
||||
return json;
|
||||
@@ -60,8 +61,8 @@ Blockly.Events.VarRename.prototype.toJson = function() {
|
||||
* Decode the JSON event.
|
||||
* @param {!Object} json JSON representation.
|
||||
*/
|
||||
Blockly.Events.VarRename.prototype.fromJson = function(json) {
|
||||
Blockly.Events.VarRename.superClass_.fromJson.call(this, json);
|
||||
VarRename.prototype.fromJson = function(json) {
|
||||
VarRename.superClass_.fromJson.call(this, json);
|
||||
this.oldName = json['oldName'];
|
||||
this.newName = json['newName'];
|
||||
};
|
||||
@@ -70,7 +71,7 @@ Blockly.Events.VarRename.prototype.fromJson = function(json) {
|
||||
* Run a variable rename event.
|
||||
* @param {boolean} forward True if run forward, false if run backward (undo).
|
||||
*/
|
||||
Blockly.Events.VarRename.prototype.run = function(forward) {
|
||||
VarRename.prototype.run = function(forward) {
|
||||
const workspace = this.getEventWorkspace_();
|
||||
if (forward) {
|
||||
workspace.renameVariableById(this.varId, this.newName);
|
||||
@@ -80,4 +81,6 @@ Blockly.Events.VarRename.prototype.run = function(forward) {
|
||||
};
|
||||
|
||||
Blockly.registry.register(Blockly.registry.Type.EVENT,
|
||||
Blockly.Events.VAR_RENAME, Blockly.Events.VarRename);
|
||||
Blockly.Events.VAR_RENAME, VarRename);
|
||||
|
||||
exports = VarRename;
|
||||
|
||||
@@ -49,10 +49,10 @@ goog.addDependency('../../core/events/events_selected.js', ['Blockly.Events.Sele
|
||||
goog.addDependency('../../core/events/events_theme_change.js', ['Blockly.Events.ThemeChange'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object']);
|
||||
goog.addDependency('../../core/events/events_toolbox_item_select.js', ['Blockly.Events.ToolboxItemSelect'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_trashcan_open.js', ['Blockly.Events.TrashcanOpen'], ['Blockly.Events', 'Blockly.Events.UiBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_var_base.js', ['Blockly.Events.VarBase'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.utils.object']);
|
||||
goog.addDependency('../../core/events/events_var_create.js', ['Blockly.Events.VarCreate'], ['Blockly.Events', 'Blockly.Events.VarBase', 'Blockly.registry', 'Blockly.utils.object']);
|
||||
goog.addDependency('../../core/events/events_var_delete.js', ['Blockly.Events.VarDelete'], ['Blockly.Events', 'Blockly.Events.VarBase', 'Blockly.registry', 'Blockly.utils.object']);
|
||||
goog.addDependency('../../core/events/events_var_rename.js', ['Blockly.Events.VarRename'], ['Blockly.Events', 'Blockly.Events.VarBase', 'Blockly.registry', 'Blockly.utils.object']);
|
||||
goog.addDependency('../../core/events/events_var_base.js', ['Blockly.Events.VarBase'], ['Blockly.Events.Abstract', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_var_create.js', ['Blockly.Events.VarCreate'], ['Blockly.Events', 'Blockly.Events.VarBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_var_delete.js', ['Blockly.Events.VarDelete'], ['Blockly.Events', 'Blockly.Events.VarBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/events/events_var_rename.js', ['Blockly.Events.VarRename'], ['Blockly.Events', 'Blockly.Events.VarBase', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
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/workspace_events.js', ['Blockly.Events.FinishedLoading'], ['Blockly.Events', 'Blockly.Events.Abstract', 'Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'});
|
||||
|
||||
Reference in New Issue
Block a user