From 8355351898662b76b4a34e4d9275c8db9db9cbe4 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Thu, 13 Jul 2023 17:18:48 -0700 Subject: [PATCH] fix: add compose and decompose errors to mutator icon (#7289) * fix: add compose and decompose errors to mutator icon * chore: format --- core/icons/mutator_icon.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/icons/mutator_icon.ts b/core/icons/mutator_icon.ts index eee9e585d..8817450ce 100644 --- a/core/icons/mutator_icon.ts +++ b/core/icons/mutator_icon.ts @@ -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) {