mirror of
https://github.com/google/blockly.git
synced 2026-01-26 02:00:10 +01:00
* chore: fixup procedure change event tests * feat: add running procedure change return events * fixup change return * feat: add running the procedure rename event * feat: add running procedure enable events * feat: add running parameter rename events * feat: add running procedure create events * feat: add running procedure delete events * feat: add running parameter create events * feat: add running procedure parameter delete events * chore: add types to all of the new procedure events * chore: format * chore: use type imports * chore: fix test comments * chore: add more inline docs
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2022 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import type {IProcedureModel} from '../interfaces/i_procedure_model.js';
|
|
import {ObservableProcedureModel} from '../procedures.js';
|
|
import * as registry from '../registry.js';
|
|
import type {Workspace} from '../workspace.js';
|
|
|
|
import {ProcedureBase} from './events_procedure_base.js';
|
|
import * as eventUtils from './utils.js';
|
|
|
|
|
|
/**
|
|
* Represents a procedure data model being created.
|
|
*/
|
|
export class ProcedureCreate extends ProcedureBase {
|
|
/** A string used to check the type of the event. */
|
|
type = eventUtils.PROCEDURE_CREATE;
|
|
|
|
constructor(workspace: Workspace, model: IProcedureModel) {
|
|
super(workspace, model);
|
|
}
|
|
|
|
run(forward: boolean) {
|
|
const workspace = this.getEventWorkspace_();
|
|
const procedureMap = workspace.getProcedureMap();
|
|
const procedureModel = procedureMap.get(this.model.getId());
|
|
if (forward) {
|
|
if (procedureModel) return;
|
|
procedureMap.add(new ObservableProcedureModel(
|
|
workspace, this.model.getName(), this.model.getId()));
|
|
} else {
|
|
if (!procedureModel) return;
|
|
procedureMap.delete(this.model.getId());
|
|
}
|
|
}
|
|
}
|
|
|
|
registry.register(
|
|
registry.Type.EVENT, eventUtils.PROCEDURE_CREATE, ProcedureCreate);
|