Skip to content

Commit

Permalink
feat: make isMutator public (google#6316)
Browse files Browse the repository at this point in the history
* feat: make isMutator public

* fix: move isFlyout and isMutator to getters

* chore: delete change detector test
  • Loading branch information
BeksOmega authored Aug 8, 2022
1 parent 3d7dc2c commit 8f4b49a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 46 deletions.
2 changes: 1 addition & 1 deletion core/flyout_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
this.workspace_.setMetricsManager(
new FlyoutMetricsManager(this.workspace_, this));

this.workspace_.isFlyout = true;
this.workspace_.internalIsFlyout = true;
// Keep the workspace visibility consistent with the flyout's visibility.
this.workspace_.setVisible(this.isVisible_);

Expand Down
2 changes: 1 addition & 1 deletion core/mutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class Mutator extends Icon {
workspaceOptions.languageTree = toolbox.convertToolboxDefToJson(quarkXml);
}
this.workspace_ = this.newWorkspaceSvg(workspaceOptions);
this.workspace_.isMutator = true;
this.workspace_.internalIsMutator = true;
this.workspace_.addChangeListener(eventUtils.disableOrphans);

// Mutator flyouts go inside the mutator workspace's <g> rather than in
Expand Down
17 changes: 15 additions & 2 deletions core/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,27 @@ export class Workspace implements IASTNodeLocation {
*/
rendered = false;

/**
* Is this workspace the surface for a flyout?
* @internal
*/
internalIsFlyout = false;

/** Is this workspace the surface for a flyout? */
isFlyout = false;
get isFlyout(): boolean {
return this.internalIsFlyout;
}

/**
* Is this workspace the surface for a mutator?
* @internal
*/
isMutator = false;
internalIsMutator = false;

/** Is this workspace the surface for a mutator? */
get isMutator(): boolean {
return this.internalIsMutator;
}

/**
* Returns `true` if the workspace is currently in the process of a bulk
Expand Down
42 changes: 0 additions & 42 deletions tests/mocha/workspace_svg_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,48 +124,6 @@ suite('WorkspaceSvg', function() {
});
});

suite('addTopBlock', function() {
setup(function() {
this.targetWorkspace = new Blockly.Workspace();
this.workspace.isFlyout = true;
this.workspace.targetWorkspace = this.targetWorkspace;
Blockly.defineBlocksWithJsonArray([{
"type": "get_var_block",
"message0": "%1",
"args0": [
{
"type": "field_variable",
"name": "VAR",
"variableTypes": ["", "type1", "type2"],
},
],
}]);
});

teardown(function() {
// Have to dispose of the main workspace after the flyout workspace
// because it holds the variable map.
// Normally the main workspace disposes of the flyout workspace.
workspaceTeardown.call(this, this.targetWorkspace);
});

test('Trivial Flyout is True', function() {
this.targetWorkspace.createVariable('name1', '', '1');

// Flyout.init usually does this binding.
this.workspace.variableMap_ = this.targetWorkspace.getVariableMap();

Blockly.Events.disable();
const block = new Blockly.Block(this.workspace, 'get_var_block');
block.inputList[0].fieldRow[0].setValue('1');
Blockly.Events.enable();

this.workspace.removeTopBlock(block);
this.workspace.addTopBlock(block);
assertVariableValues(this.workspace, 'name1', '', '1');
});
});

suite('Viewport change events', function() {
function resetEventHistory(eventsFireStub, changeListenerSpy) {
eventsFireStub.resetHistory();
Expand Down

0 comments on commit 8f4b49a

Please sign in to comment.