waveterm/frontend/builder
Copilot 705563ebe0
Refactor ContextMenuModel to lazy singleton via getInstance() and update all call sites (#2920)
`contextmenu.ts` eagerly instantiated its model at import time, which
triggered constructor side effects (`getApi()`) too early. This change
aligns ContextMenuModel with the `client-model.ts` singleton pattern so
initialization is explicit and deferred.

- **Singleton pattern migration (`frontend/app/store/contextmenu.ts`)**
- Replaced eager module-level instance creation with a class-based
singleton:
    - `private constructor()`
    - `static getInstance()`
- Removed `ContextMenuModelType` export and now export
`ContextMenuModel` class only.
- Constructor side effects (`onContextMenuClick` wiring) now run only on
first `getInstance()` call.

- **Usage updates (all context menu entry points)**
  - Updated all direct static-style calls:
    - `ContextMenuModel.showContextMenu(...)`
    - ⟶ `ContextMenuModel.getInstance().showContextMenu(...)`
- Applied across app/builder/preview/term/tab/widget context-menu
handlers to keep behavior consistent while deferring initialization.

- **Focused regression test**
  - Added `frontend/app/store/contextmenu.test.ts` to verify:
    - importing `contextmenu` does not initialize the API binding;
    - first `getInstance()` initializes once;
    - repeated `getInstance()` returns the same singleton instance.

```ts
// before
ContextMenuModel.showContextMenu(menu, e);

// after
ContextMenuModel.getInstance().showContextMenu(menu, e);
```

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
2026-02-23 13:42:02 -08:00
..
store Generate WaveEvent as a typed discriminated union with explicit null payloads for no-data events (#2899) 2026-02-20 17:04:03 -08:00
tabs Refactor ContextMenuModel to lazy singleton via getInstance() and update all call sites (#2920) 2026-02-23 13:42:02 -08:00
utils tsunami app builder 2 (#2486) 2025-10-27 16:37:15 -07:00
app-selection-modal.tsx more builder updates (#2553) 2025-11-13 22:47:46 -08:00
builder-app.tsx More Builder Improvements + Tsunami AppInit (#2571) 2025-11-19 09:41:11 -08:00
builder-apppanel.tsx Refactor ContextMenuModel to lazy singleton via getInstance() and update all call sites (#2920) 2026-02-23 13:42:02 -08:00
builder-buildpanel.tsx Refactor ContextMenuModel to lazy singleton via getInstance() and update all call sites (#2920) 2026-02-23 13:42:02 -08:00
builder-workspace.tsx More Builder Improvements + Tsunami AppInit (#2571) 2025-11-19 09:41:11 -08:00