Subskill: Logic Consolidator (Pass 1)
This subskill extracts manual layout building, attribute modifications, and
rendering loops out of the constructor and scattered event handlers,
consolidating them into private helper methods with explicit data contracts.
1. Logic Consolidation Rules
- Identify UI updates Creation:
- Scan the class constructor and search for manual DOM operations (e.g.,
element.createChild('div'), document.createElement,
element.appendChild).
- Also look for any UI updates which call lit-html
render.
- Isolate Update and Draw Operations:
- Group the imperative creation/update lines into dedicated private helper
methods (e.g., #updateSummaryBar(...) or #createEditorToolbar(...)).
- Group event-handling updates (e.g., state variables like
pageSize,
modified during buttons clicks) into centralized functions like
onPageSizeChanged.
- Define the State Interface:
- Identify the class state and ensure it is captured in the private member
variables, e.g.
```typescript
#entries: Entry[];
#canGoBack: boolean;
#canGoForward: boolean;
#staleWarningVisible: boolean;
```
- Replace direct mutations of UI with updates to these
#privatemember
variables, then trigger a single consolidated update path:
- Logic First (imperative constructor DOM remains): Call a private
imperative helper (e.g., this.#updateUI()) that updates existing
element references in place (inlining if there are only one or two
update helpers). Do not call this.performUpdate() synchronously
on state updates.
- Lit First (Lit template already owns the container): Schedule
asynchronous updates via this.requestUpdate().
- Extract/Consolidate Rendering Operations:
- If Logic First (imperative constructor DOM remains), route all UI
mutations through private #update*() helpers. Never define
override performUpdate() calling render(..., this.contentElement)
while imperative constructor DOM on this.contentElement still exists,
because instantiateWidget() calls requestUpdate() automatically and
prepends duplicate DOM nodes and IDs alongside the constructor children.
- If Lit First (Lit template already exists), make sure there's a single
master call to Lit render inside performUpdate. The master template
might include calls to the helper functions e.g.
```typescript
render(html`
<div class="specific-view">
<span>View Title</span>
${this.renderOverviewSection()}
</div>
`, this.contentElement);
```
- Minimize Diffs (Safety Rule):
- Avoid moving existing code to a different location in the file. Put the
function signature around the existing code to minimize the diff.
- The Gerrit Code Review UI cannot identify moved blocks of unchanged
code.
- If blocks of code need to be reordered, create a "prefactoring" change
that first extracts the code that needs to be reordered into named
helper functions and pause the migration, waiting for user confirmation.
- No Write-Only State Fields in Prefactor CLs:
- Do not introduce
#statefields in a logic-consolidation CL that are only
written to in that CL and only read in the next CL's DEFAULT_VIEW.
- Either read them in the prefactor CL (e.g., inside an extracted imperative
#render... helper) or introduce them in the CL that actually adds
DEFAULT_VIEW.
- Extract Imperative
#renderSubtreeContent()Helpers:
- For complex layouts, extracting an imperative
#renderFooContent()
helper in Pass 1 (while keeping the outer container imperative) minimizes
the Pass 2/3 diff when converting #renderFooContent() to
renderFooContent(input: ViewInput): LitTemplate.
- Preserve Imperative Cleanup Calls:
- When consolidating DOM/widget references (e.g., replacing
#tabbedLocationHeader with #debuggerSidebarTabbedLocation), preserve
imperative cleanup calls like splitWidget.uninstallResizer(...) until the
imperative container itself is removed.
- Wait for confirmation:
- Wait for an explicit confirmation from the user (or Parent Orchestrator Agent) before proceeding to the next step.
🔍 Mental Audit (Internal Self-Correction)
Before reporting back or committing, re-read the instructions and verify:
- ❓ Minimal Diffs: Did I move code blocks around unnecessarily?
- ❓ State Completeness & Utility: Are all state variables actually read in this CL, with no write-only placeholders?
- ❓ Cleanup Preserved: Are resizer/listener uninstallation calls preserved during reference consolidation?
- ❓ Build: Does the code still compile?
- ❓ No Premature
performUpdate(): Did I avoid synchronousperformUpdate()calls on state updates and avoidrender(..., this.contentElement)while imperative constructor DOM remains?