mirror of
https://github.com/wavetermdev/waveterm
synced 2026-05-24 09:18:27 +00:00
`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>
|
||
|---|---|---|
| .. | ||
| builder-codetab.tsx | ||
| builder-configdatatab.tsx | ||
| builder-filestab.tsx | ||
| builder-previewtab.tsx | ||
| builder-secrettab.tsx | ||