Skip to content

Commit

Permalink
chore: Remove underscores from private fields. (#8682)
Browse files Browse the repository at this point in the history
* chore: Remove underscores from private fields.

* refactor: Use public APIs in tests where possible.
  • Loading branch information
gonfunko authored Dec 2, 2024
1 parent 6f3f884 commit 61bbd7d
Show file tree
Hide file tree
Showing 40 changed files with 378 additions and 401 deletions.
126 changes: 61 additions & 65 deletions core/block.ts

Large diffs are not rendered by default.

40 changes: 13 additions & 27 deletions core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class BlockSvg
/** Block's mutator icon (if any). */
mutator: MutatorIcon | null = null;

private svgGroup_: SVGGElement;
private svgGroup: SVGGElement;
style: BlockStyle;
/** @internal */
pathObject: IPathObject;
Expand All @@ -155,15 +155,6 @@ export class BlockSvg

private visuallyDisabled = false;

/**
* Is this block currently rendering? Used to stop recursive render calls
* from actually triggering a re-render.
*/
private renderIsInProgress_ = false;

/** Whether mousedown events have been bound yet. */
private eventsInit_ = false;

override workspace: WorkspaceSvg;
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
override outputConnection!: RenderedConnection;
Expand Down Expand Up @@ -201,22 +192,22 @@ export class BlockSvg
throw TypeError('Cannot create a rendered block in a headless workspace');
}
this.workspace = workspace;
this.svgGroup_ = dom.createSvgElement(Svg.G, {});
this.svgGroup = dom.createSvgElement(Svg.G, {});

/** A block style object. */
this.style = workspace.getRenderer().getConstants().getBlockStyle(null);

/** The renderer's path object. */
this.pathObject = workspace
.getRenderer()
.makePathObject(this.svgGroup_, this.style);
.makePathObject(this.svgGroup, this.style);

const svgPath = this.pathObject.svgPath;
(svgPath as any).tooltip = this;
Tooltip.bindMouseEvents(svgPath);

// Expose this block's ID on its top-level SVG group.
this.svgGroup_.setAttribute('data-id', this.id);
this.svgGroup.setAttribute('data-id', this.id);

this.doInit_();
}
Expand All @@ -238,12 +229,7 @@ export class BlockSvg
this.pathObject.updateMovable(this.isMovable() || this.isInFlyout);
const svg = this.getSvgRoot();
if (!this.workspace.options.readOnly && svg) {
browserEvents.conditionalBind(
svg,
'pointerdown',
this,
this.onMouseDown_,
);
browserEvents.conditionalBind(svg, 'pointerdown', this, this.onMouseDown);
}

if (!svg.parentNode) {
Expand Down Expand Up @@ -518,14 +504,14 @@ export class BlockSvg
return;
}
super.setCollapsed(collapsed);
this.updateCollapsed_();
this.updateCollapsed();
}

/**
* Makes sure that when the block is collapsed, it is rendered correctly
* for that state.
*/
private updateCollapsed_() {
private updateCollapsed() {
const collapsed = this.isCollapsed();
const collapsedInputName = constants.COLLAPSED_INPUT_NAME;
const collapsedFieldName = constants.COLLAPSED_FIELD_NAME;
Expand Down Expand Up @@ -592,7 +578,7 @@ export class BlockSvg
*
* @param e Pointer down event.
*/
private onMouseDown_(e: PointerEvent) {
private onMouseDown(e: PointerEvent) {
const gesture = this.workspace.getGesture(e);
if (gesture) {
gesture.handleBlockStart(e, this);
Expand Down Expand Up @@ -702,10 +688,10 @@ export class BlockSvg
if (adding) {
this.translation = '';
common.draggingConnections.push(...this.getConnections_(true));
dom.addClass(this.svgGroup_, 'blocklyDragging');
dom.addClass(this.svgGroup, 'blocklyDragging');
} else {
common.draggingConnections.length = 0;
dom.removeClass(this.svgGroup_, 'blocklyDragging');
dom.removeClass(this.svgGroup, 'blocklyDragging');
}
// Recurse through all blocks attached under this one.
for (let i = 0; i < this.childBlocks_.length; i++) {
Expand Down Expand Up @@ -775,7 +761,7 @@ export class BlockSvg
* @returns The root SVG node (probably a group).
*/
getSvgRoot(): SVGGElement {
return this.svgGroup_;
return this.svgGroup;
}

/**
Expand Down Expand Up @@ -817,7 +803,7 @@ export class BlockSvg
}

super.dispose(!!healStack);
dom.removeNode(this.svgGroup_);
dom.removeNode(this.svgGroup);
}

/**
Expand Down Expand Up @@ -1565,7 +1551,7 @@ export class BlockSvg
dom.startTextWidthCache();

if (this.isCollapsed()) {
this.updateCollapsed_();
this.updateCollapsed();
}

if (!this.isEnabled()) {
Expand Down
6 changes: 3 additions & 3 deletions core/component_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Capability<_T> {
static DRAG_TARGET = new Capability<IDragTarget>('drag_target');
static DELETE_AREA = new Capability<IDeleteArea>('delete_area');
static AUTOHIDEABLE = new Capability<IAutoHideable>('autohideable');
private readonly name_: string;
private readonly name: string;
/** @param name The name of the component capability. */
constructor(name: string) {
this.name_ = name;
this.name = name;
}

/**
Expand All @@ -35,7 +35,7 @@ class Capability<_T> {
* @returns The name.
*/
toString(): string {
return this.name_;
return this.name;
}
}

Expand Down
16 changes: 8 additions & 8 deletions core/contextmenu_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {WorkspaceSvg} from './workspace_svg.js';
export class ContextMenuRegistry {
static registry: ContextMenuRegistry;
/** Registry of all registered RegistryItems, keyed by ID. */
private registry_ = new Map<string, RegistryItem>();
private registeredItems = new Map<string, RegistryItem>();

/** Resets the existing singleton instance of ContextMenuRegistry. */
constructor() {
Expand All @@ -32,7 +32,7 @@ export class ContextMenuRegistry {

/** Clear and recreate the registry. */
reset() {
this.registry_.clear();
this.registeredItems.clear();
}

/**
Expand All @@ -42,10 +42,10 @@ export class ContextMenuRegistry {
* @throws {Error} if an item with the given ID already exists.
*/
register(item: RegistryItem) {
if (this.registry_.has(item.id)) {
if (this.registeredItems.has(item.id)) {
throw Error('Menu item with ID "' + item.id + '" is already registered.');
}
this.registry_.set(item.id, item);
this.registeredItems.set(item.id, item);
}

/**
Expand All @@ -55,18 +55,18 @@ export class ContextMenuRegistry {
* @throws {Error} if an item with the given ID does not exist.
*/
unregister(id: string) {
if (!this.registry_.has(id)) {
if (!this.registeredItems.has(id)) {
throw new Error('Menu item with ID "' + id + '" not found.');
}
this.registry_.delete(id);
this.registeredItems.delete(id);
}

/**
* @param id The ID of the RegistryItem to get.
* @returns RegistryItem or null if not found
*/
getItem(id: string): RegistryItem | null {
return this.registry_.get(id) ?? null;
return this.registeredItems.get(id) ?? null;
}

/**
Expand All @@ -85,7 +85,7 @@ export class ContextMenuRegistry {
scope: Scope,
): ContextMenuOption[] {
const menuOptions: ContextMenuOption[] = [];
for (const item of this.registry_.values()) {
for (const item of this.registeredItems.values()) {
if (scopeType === item.scopeType) {
const precondition = item.preconditionFn(scope);
if (precondition !== 'hidden') {
Expand Down
6 changes: 3 additions & 3 deletions core/events/events_block_move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class BlockMove extends BlockBase {
this.recordUndo = false;
}

const location = this.currentLocation_();
const location = this.currentLocation();
this.oldParentId = location.parentId;
this.oldInputName = location.inputName;
this.oldCoordinate = location.coordinate;
Expand Down Expand Up @@ -167,7 +167,7 @@ export class BlockMove extends BlockBase {

/** Record the block's new location. Called after the move. */
recordNew() {
const location = this.currentLocation_();
const location = this.currentLocation();
this.newParentId = location.parentId;
this.newInputName = location.inputName;
this.newCoordinate = location.coordinate;
Expand All @@ -188,7 +188,7 @@ export class BlockMove extends BlockBase {
*
* @returns Collection of location info.
*/
private currentLocation_(): BlockLocation {
private currentLocation(): BlockLocation {
const workspace = this.getEventWorkspace_();
if (!this.blockId) {
throw new Error(
Expand Down
36 changes: 18 additions & 18 deletions core/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ export abstract class Field<T = any>
* Used to cache the field's tooltip value if setTooltip is called when the
* field is not yet initialized. Is *not* guaranteed to be accurate.
*/
private tooltip_: Tooltip.TipInfo | null = null;
private tooltip: Tooltip.TipInfo | null = null;
protected size_: Size;

/**
* Holds the cursors svg element when the cursor is attached to the field.
* This is null if there is no cursor on the field.
*/
private cursorSvg_: SVGElement | null = null;
private cursorSvg: SVGElement | null = null;

/**
* Holds the markers svg element when the marker is attached to the field.
* This is null if there is no marker on the field.
*/
private markerSvg_: SVGElement | null = null;
private markerSvg: SVGElement | null = null;

/** The rendered field's SVG group element. */
protected fieldGroup_: SVGGElement | null = null;
Expand All @@ -135,7 +135,7 @@ export abstract class Field<T = any>
protected textContent_: Text | null = null;

/** Mouse down event listener data. */
private mouseDownWrapper_: browserEvents.Data | null = null;
private mouseDownWrapper: browserEvents.Data | null = null;

/** Constants associated with the source block's renderer. */
protected constants_: ConstantProvider | null = null;
Expand Down Expand Up @@ -312,7 +312,7 @@ export abstract class Field<T = any>
sourceBlockSvg.getSvgRoot().appendChild(this.fieldGroup_);
this.initView();
this.updateEditable();
this.setTooltip(this.tooltip_);
this.setTooltip(this.tooltip);
this.bindEvents_();
this.initModel();
this.applyColour();
Expand Down Expand Up @@ -393,7 +393,7 @@ export abstract class Field<T = any>
const clickTarget = this.getClickTarget_();
if (!clickTarget) throw new Error('A click target has not been set.');
Tooltip.bindMouseEvents(clickTarget);
this.mouseDownWrapper_ = browserEvents.conditionalBind(
this.mouseDownWrapper = browserEvents.conditionalBind(
clickTarget,
'pointerdown',
this,
Expand Down Expand Up @@ -1095,7 +1095,7 @@ export abstract class Field<T = any>

try {
const classValidation = this.doClassValidation_(newValue);
const classValue = this.processValidation_(
const classValue = this.processValidation(
newValue,
classValidation,
fireChangeEvent,
Expand All @@ -1106,7 +1106,7 @@ export abstract class Field<T = any>
}

const localValidation = this.getValidator()?.call(this, classValue);
const localValue = this.processValidation_(
const localValue = this.processValidation(
classValue,
localValidation,
fireChangeEvent,
Expand Down Expand Up @@ -1158,7 +1158,7 @@ export abstract class Field<T = any>
* @param fireChangeEvent Whether to fire a change event if the value changes.
* @returns New value, or an Error object.
*/
private processValidation_(
private processValidation(
newValue: AnyDuringMigration,
validatedValue: T | null | undefined,
fireChangeEvent: boolean,
Expand Down Expand Up @@ -1272,7 +1272,7 @@ export abstract class Field<T = any>
(clickTarget as AnyDuringMigration).tooltip = newTip;
} else {
// Field has not been initialized yet.
this.tooltip_ = newTip;
this.tooltip = newTip;
}
}

Expand All @@ -1286,8 +1286,8 @@ export abstract class Field<T = any>
if (clickTarget) {
return Tooltip.getTooltipOfObject(clickTarget);
}
// Field has not been initialized yet. Return stashed this.tooltip_ value.
return Tooltip.getTooltipOfObject({tooltip: this.tooltip_});
// Field has not been initialized yet. Return stashed this.tooltip value.
return Tooltip.getTooltipOfObject({tooltip: this.tooltip});
}

/**
Expand Down Expand Up @@ -1396,15 +1396,15 @@ export abstract class Field<T = any>
*/
setCursorSvg(cursorSvg: SVGElement) {
if (!cursorSvg) {
this.cursorSvg_ = null;
this.cursorSvg = null;
return;
}

if (!this.fieldGroup_) {
throw new Error(`The field group is ${this.fieldGroup_}.`);
}
this.fieldGroup_.appendChild(cursorSvg);
this.cursorSvg_ = cursorSvg;
this.cursorSvg = cursorSvg;
}

/**
Expand All @@ -1415,15 +1415,15 @@ export abstract class Field<T = any>
*/
setMarkerSvg(markerSvg: SVGElement) {
if (!markerSvg) {
this.markerSvg_ = null;
this.markerSvg = null;
return;
}

if (!this.fieldGroup_) {
throw new Error(`The field group is ${this.fieldGroup_}.`);
}
this.fieldGroup_.appendChild(markerSvg);
this.markerSvg_ = markerSvg;
this.markerSvg = markerSvg;
}

/**
Expand All @@ -1437,10 +1437,10 @@ export abstract class Field<T = any>
throw new UnattachedFieldError();
}
const workspace = block.workspace as WorkspaceSvg;
if (workspace.keyboardAccessibilityMode && this.cursorSvg_) {
if (workspace.keyboardAccessibilityMode && this.cursorSvg) {
workspace.getCursor()!.draw();
}
if (workspace.keyboardAccessibilityMode && this.markerSvg_) {
if (workspace.keyboardAccessibilityMode && this.markerSvg) {
// TODO(#4592): Update all markers on the field.
workspace.getMarker(MarkerManager.LOCAL_MARKER)!.draw();
}
Expand Down
Loading

0 comments on commit 61bbd7d

Please sign in to comment.