mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user