fix: add compose and decompose errors to mutator icon (#7289)

* fix: add compose and decompose errors to mutator icon

* chore: format
This commit is contained in:
Beka Westberg
2023-07-13 17:18:48 -07:00
committed by GitHub
parent 741e8dbebb
commit 8355351898

View File

@@ -227,7 +227,12 @@ export class MutatorIcon extends Icon implements IHasBubble {
/** Decomposes the source block to create blocks in the mini workspace. */
private createRootBlock() {
this.rootBlock = this.sourceBlock.decompose!(
if (!this.sourceBlock.decompose) {
throw new Error(
'Blocks with mutator icons must include a decompose method'
);
}
this.rootBlock = this.sourceBlock.decompose(
this.miniWorkspaceBubble!.getWorkspace()
)!;
@@ -290,12 +295,17 @@ export class MutatorIcon extends Icon implements IHasBubble {
/** Recomposes the source block based on changes to the mini workspace. */
private recomposeSourceBlock() {
if (!this.rootBlock) return;
if (!this.sourceBlock.compose) {
throw new Error(
'Blocks with mutator icons must include a compose method'
);
}
const existingGroup = eventUtils.getGroup();
if (!existingGroup) eventUtils.setGroup(true);
const oldExtraState = BlockChange.getExtraBlockState_(this.sourceBlock);
this.sourceBlock.compose!(this.rootBlock);
this.sourceBlock.compose(this.rootBlock);
const newExtraState = BlockChange.getExtraBlockState_(this.sourceBlock);
if (oldExtraState !== newExtraState) {