Files
blockly/core/events/workspace_events.ts
2022-07-07 22:22:51 +00:00

86 lines
2.1 KiB
TypeScript

/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Class for a finished loading workspace event.
*/
/**
* Class for a finished loading workspace event.
* @class
*/
import * as registry from '../registry';
import type {Workspace} from '../workspace';
import {Abstract as AbstractEvent} from './events_abstract';
import * as eventUtils from './utils';
/**
* 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.
* @alias Blockly.Events.FinishedLoading
*/
export class FinishedLoading extends AbstractEvent {
override isBlank: boolean;
override workspaceId: string;
// Workspace events do not undo or redo.
override recordUndo = false;
override type: string;
override group: AnyDuringMigration;
/**
* @param opt_workspace The workspace that has finished loading. Undefined
* for a blank event.
*/
constructor(opt_workspace?: Workspace) {
super();
/** Whether or not the event is blank (to be populated by fromJson). */
this.isBlank = typeof opt_workspace === 'undefined';
/** The workspace identifier for this event. */
this.workspaceId = opt_workspace ? opt_workspace.id : '';
/** Type of this event. */
this.type = eventUtils.FINISHED_LOADING;
}
/**
* Encode the event as JSON.
* @return JSON representation.
*/
override toJson(): AnyDuringMigration {
const json = {
'type': this.type,
};
if (this.group) {
(json as AnyDuringMigration)['group'] = this.group;
}
if (this.workspaceId) {
(json as AnyDuringMigration)['workspaceId'] = this.workspaceId;
}
return json;
}
/**
* Decode the JSON event.
* @param json JSON representation.
*/
override fromJson(json: AnyDuringMigration) {
this.isBlank = false;
this.workspaceId = json['workspaceId'];
this.group = json['group'];
}
}
registry.register(
registry.Type.EVENT, eventUtils.FINISHED_LOADING, FinishedLoading);