Skip to content

refactor(pitchdrummatrix): extract duplicated play-button icon construction - #7990

Open
Sumanthvu wants to merge 1 commit into
sugarlabs:masterfrom
Sumanthvu:refactor/pitchdrummatrix-extract-helpers
Open

refactor(pitchdrummatrix): extract duplicated play-button icon construction#7990
Sumanthvu wants to merge 1 commit into
sugarlabs:masterfrom
Sumanthvu:refactor/pitchdrummatrix-extract-helpers

Conversation

@Sumanthvu

@Sumanthvu Sumanthvu commented Aug 8, 2026

Copy link
Copy Markdown

Summary

Extract the play/stop button icon construction in PitchDrumMatrix._playAll() into a reusable _setPlayButtonIcon(state) helper.

Problem

The _playAll() method contained four nearly identical 12-line blocks that construct a play or stop button icon. Each block:

  • Clears the button's textContent
  • Creates an <img> element with src, title, alt, and sizing attributes
  • Appends the image and a trailing spacer text node

The only difference between copies is the icon source (play-button.svg vs stop-button.svg) and the label text ("Play" vs "Stop").

Changes

js/widgets/pitchdrummatrix.js

  • New method: _setPlayButtonIcon(state) — accepts "play" or "stop", performs the icon construction once.
  • Simplified _playAll() — replaced four copy-paste blocks with single-line calls to the new helper.
  • No behavioral change — this is a pure refactoring.

js/widgets/__tests__/pitchdrummatrix.test.js

  • Added four focused tests for _setPlayButtonIcon:
    • Verifies DOM structure for both play and stop states.
    • Verifies correct src, title, and alt attributes.

Verification

PR Category

Please check at least one category:

  • Bug Fix
  • Feature
  • Performance
  • Tests
  • Refactoring

…uction

The _playAll() method contained four nearly identical copies of the play/stop button icon construction pattern (12 lines each). Extract this into a single _setPlayButtonIcon(state) helper that accepts 'play' or 'stop'.

Add four focused tests for the new helper covering both icon states and their DOM attributes.
@github-actions github-actions Bot added tests Adds or updates test coverage size/M Medium: 50-249 lines changed area/javascript Changes to JS source files area/tests Changes to test files performance Improves performance (load time, memory, rendering) and removed performance Improves performance (load time, memory, rendering) labels Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/javascript Changes to JS source files area/tests Changes to test files size/M Medium: 50-249 lines changed tests Adds or updates test coverage

Projects

Development

Successfully merging this pull request may close these issues.

1 participant