mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
chore: update procedure map tests to match the refactored API (#6562)
* fix: feedback on procedure model implementations * chore: format * chore: add tests for the backing variable of parameter models * chore: update existing procedure map tests * chore: update block update tests to use refactored API * chore: update tests to actually use fluent API * chore: format * chore: fix tests * chore: reorganize tests * chore: format * chore: add comment
This commit is contained in:
@@ -602,6 +602,7 @@ export {Css};
|
||||
export {Events};
|
||||
export {Extensions};
|
||||
export {Procedures};
|
||||
export {Procedures as procedures};
|
||||
export {ShortcutItems};
|
||||
export {Themes};
|
||||
export {Tooltip};
|
||||
|
||||
@@ -25,6 +25,9 @@ import * as eventUtils from './events/utils.js';
|
||||
import {Field, UnattachedFieldError} from './field.js';
|
||||
import {Msg} from './msg.js';
|
||||
import {Names} from './names.js';
|
||||
import {ObservableProcedureMap} from './procedures/observable_procedure_map.js';
|
||||
import {ObservableProcedureModel} from './procedures/observable_procedure_model.js';
|
||||
import {ObservableParameterModel} from './procedures/observable_parameter_model.js';
|
||||
import * as utilsXml from './utils/xml.js';
|
||||
import * as Variables from './variables.js';
|
||||
import type {Workspace} from './workspace.js';
|
||||
@@ -450,3 +453,9 @@ export function getDefinition(name: string, workspace: Workspace): Block|null {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export {
|
||||
ObservableProcedureMap,
|
||||
ObservableProcedureModel,
|
||||
ObservableParameterModel,
|
||||
};
|
||||
|
||||
@@ -17,13 +17,15 @@ export class ObservableParameterModel implements IParameterModel {
|
||||
constructor(
|
||||
private readonly workspace: Workspace, name: string, id?: string) {
|
||||
this.id = id ?? genUid();
|
||||
this.variable = workspace.createVariable(name);
|
||||
this.variable =
|
||||
this.workspace.getVariable(name) ?? workspace.createVariable(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of this parameter to the given name.
|
||||
*/
|
||||
setName(name: string): this {
|
||||
// TODO(#6516): Fire events.
|
||||
if (name == this.variable.name) return this;
|
||||
this.variable =
|
||||
this.workspace.getVariable(name) ?? this.workspace.createVariable(name);
|
||||
@@ -34,12 +36,14 @@ export class ObservableParameterModel implements IParameterModel {
|
||||
* Unimplemented. The built-in ParameterModel does not support typing.
|
||||
* If you want your procedure blocks to have typed parameters, you need to
|
||||
* implement your own ParameterModel.
|
||||
*
|
||||
* @throws Throws for the ObservableParameterModel specifically because this
|
||||
* method is unimplemented.
|
||||
*/
|
||||
setTypes(_types: string[]): this {
|
||||
console.warn(
|
||||
throw new Error(
|
||||
'The built-in ParameterModel does not support typing. You need to ' +
|
||||
'implement your own custom ParameterModel.');
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,7 @@ export class ObservableProcedureMap extends Map<string, IProcedureModel> {
|
||||
* Adds the given procedure model to the procedure map.
|
||||
*/
|
||||
override set(id: string, proc: IProcedureModel): this {
|
||||
// TODO(#6156): Fire events.
|
||||
// TODO(#6516): Fire events.
|
||||
super.set(id, proc);
|
||||
return this;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export class ObservableProcedureMap extends Map<string, IProcedureModel> {
|
||||
* exists).
|
||||
*/
|
||||
override delete(id: string): boolean {
|
||||
// TODO(#6156): Fire events.
|
||||
// TODO(#6516): Fire events.
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export class ObservableProcedureMap extends Map<string, IProcedureModel> {
|
||||
* Removes all ProcedureModels from the procedure map.
|
||||
*/
|
||||
override clear() {
|
||||
// TODO(#6156): Fire events.
|
||||
// TODO(#6516): Fire events.
|
||||
super.clear();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ export class ObservableProcedureMap extends Map<string, IProcedureModel> {
|
||||
* blocks can find it.
|
||||
*/
|
||||
add(proc: IProcedureModel): this {
|
||||
// TODO(#6156): Fire events.
|
||||
// TODO(#6516): Fire events.
|
||||
// TODO(#6526): See if this method is actually useful.
|
||||
return this.set(proc.getId(), proc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ export class ObservableProcedureModel implements IProcedureModel {
|
||||
|
||||
/** Sets the human-readable name of the procedure. */
|
||||
setName(name: string): this {
|
||||
// TODO(#6516): Fire events.
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
@@ -33,12 +34,14 @@ export class ObservableProcedureModel implements IProcedureModel {
|
||||
* To move a parameter, first delete it, and then re-insert.
|
||||
*/
|
||||
insertParameter(parameterModel: IParameterModel, index: number): this {
|
||||
// TODO(#6516): Fire events.
|
||||
this.parameters.splice(index, 0, parameterModel);
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Removes the parameter at the given index from the parameter list. */
|
||||
deleteParameter(index: number): this {
|
||||
// TODO(#6516): Fire events.
|
||||
this.parameters.splice(index, 1);
|
||||
return this;
|
||||
}
|
||||
@@ -49,6 +52,7 @@ export class ObservableProcedureModel implements IProcedureModel {
|
||||
* Pass null to represent a procedure that does not return.
|
||||
*/
|
||||
setReturnTypes(types: string[]|null): this {
|
||||
// TODO(#6516): Fire events.
|
||||
this.returnTypes = types;
|
||||
return this;
|
||||
}
|
||||
@@ -58,6 +62,7 @@ export class ObservableProcedureModel implements IProcedureModel {
|
||||
* all procedure caller blocks should be disabled as well.
|
||||
*/
|
||||
setEnabled(enabled: boolean): this {
|
||||
// TODO(#6516): Fire events.
|
||||
this.enabled = enabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user