Skip to content

Commit 51daedd

Browse files
Copilotsawka
andauthored
Extract counters API from global store into dedicated module (#2897)
This refactor moves the counters helpers out of `frontend/app/store/global.ts` into a dedicated `counters.ts` module, and updates existing call sites to import from the new location. The goal is to keep `global.ts` focused on global store/state concerns while preserving current counters behavior. - **Module extraction** - Added `frontend/app/store/counters.ts` containing: - `counterInc(name, incAmt = 1)` - `countersClear()` - `countersPrint()` - Moved logic unchanged from `global.ts`. - **Global store cleanup** - Removed counters state/functions from `frontend/app/store/global.ts`. - Removed counters exports from `global.ts`’s export surface. - **Call site updates** - Updated imports to use `@/store/counters` in: - `frontend/app/block/block.tsx` (`counterInc`) - `frontend/wave.ts` (`countersClear`, `countersPrint`) ```ts // before import { counterInc } from "@/store/global"; // after import { counterInc } from "@/store/counters"; ``` <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
1 parent 1840de4 commit 51daedd

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

frontend/app/block/block.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { VDomModel } from "@/app/view/vdom/vdom-model";
1818
import { ErrorBoundary } from "@/element/errorboundary";
1919
import { CenteredDiv } from "@/element/quickelems";
2020
import { useDebouncedNodeInnerRect } from "@/layout/index";
21+
import { counterInc } from "@/store/counters";
2122
import {
22-
counterInc,
2323
getBlockComponentModel,
2424
registerBlockComponentModel,
2525
unregisterBlockComponentModel,

frontend/app/store/counters.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025, Command Line Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
const Counters = new Map<string, number>();
5+
6+
function countersClear() {
7+
Counters.clear();
8+
}
9+
10+
function counterInc(name: string, incAmt: number = 1) {
11+
let count = Counters.get(name) ?? 0;
12+
count += incAmt;
13+
Counters.set(name, count);
14+
}
15+
16+
function countersPrint() {
17+
let outStr = "";
18+
for (const [name, count] of Counters.entries()) {
19+
outStr += `${name}: ${count}\n`;
20+
}
21+
console.log(outStr);
22+
}
23+
24+
export { counterInc, countersClear, countersPrint };

frontend/app/store/global.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ let atoms: GlobalAtomsType;
3737
let globalEnvironment: "electron" | "renderer";
3838
let globalPrimaryTabStartup: boolean = false;
3939
const blockComponentModelMap = new Map<string, BlockComponentModel>();
40-
const Counters = new Map<string, number>();
4140
const ConnStatusMapAtom = atom(new Map<string, PrimitiveAtom<ConnStatus>>());
4241
const TabIndicatorMap = new Map<string, PrimitiveAtom<TabIndicator>>();
4342
const orefAtomCache = new Map<string, Map<string, Atom<any>>>();
@@ -740,24 +739,6 @@ function refocusNode(blockId: string) {
740739
}
741740
}
742741

743-
function countersClear() {
744-
Counters.clear();
745-
}
746-
747-
function counterInc(name: string, incAmt: number = 1) {
748-
let count = Counters.get(name) ?? 0;
749-
count += incAmt;
750-
Counters.set(name, count);
751-
}
752-
753-
function countersPrint() {
754-
let outStr = "";
755-
for (const [name, count] of Counters.entries()) {
756-
outStr += `${name}: ${count}\n`;
757-
}
758-
console.log(outStr);
759-
}
760-
761742
async function loadConnStatus() {
762743
const connStatusArr = await ClientService.GetAllConnStatus();
763744
if (connStatusArr == null) {
@@ -967,9 +948,6 @@ export {
967948
atoms,
968949
clearAllTabIndicators,
969950
clearTabIndicatorFromFocus,
970-
counterInc,
971-
countersClear,
972-
countersPrint,
973951
createBlock,
974952
createBlockSplitHorizontally,
975953
createBlockSplitVertically,

frontend/wave.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ import { makeBuilderRouteId, makeTabRouteId } from "@/app/store/wshrouter";
1717
import { initWshrpc, TabRpcClient } from "@/app/store/wshrpcutil";
1818
import { BuilderApp } from "@/builder/builder-app";
1919
import { getLayoutModelForStaticTab } from "@/layout/index";
20+
import { countersClear, countersPrint } from "@/store/counters";
2021
import {
2122
atoms,
22-
countersClear,
23-
countersPrint,
2423
getApi,
2524
globalStore,
2625
initGlobal,

0 commit comments

Comments
 (0)