Skip to content

Commit 6f9eebc

Browse files
committed
fix: would this work?
1 parent e8c44d6 commit 6f9eebc

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

src/components/bar/modules/cpu/index.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,22 @@ const getBarGraph = (usage: number): string => {
4141
return '█';
4242
};
4343

44-
const graphBinding = showGraph
45-
? Variable.derive([bind(cpuUsage), historyLengthBinding()], (cpuUsg: number, hstLength: number) => {
46-
const history = cpuHistory.get();
47-
history.push(cpuUsg);
48-
if (history.length > hstLength) {
49-
history.shift();
50-
}
51-
cpuHistory.set(history);
44+
const graphBinding = Variable.derive(
45+
[bind(showGraph), bind(cpuUsage), historyLengthBinding()],
46+
(show, cpuUsg: number, hstLength: number) => {
47+
if (!show) return '';
48+
49+
const history = cpuHistory.get();
50+
history.push(cpuUsage.percentage);
51+
if (history.length > hstLength) {
52+
history.shift();
53+
}
54+
cpuHistory.set(history);
55+
56+
return history.map(getBarGraph).join('');
57+
}
58+
);
5259

53-
return history.map(getBarGraph).join('');
54-
})
55-
: Variable.derive([], () => '');
5660

5761
export const Cpu = (): BarBoxChild => {
5862
const percentageBinding = Variable.derive([bind(cpuUsage), bind(round)], (cpuUsg: number, round: boolean) => {

src/components/bar/modules/ram/index.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,22 @@ const getBarGraph = (usage: number): string => {
3939
return '█';
4040
};
4141

42-
const graphBinding = showGraph
43-
? Variable.derive([bind(ramUsage), historyLengthBinding()], (rmUsg: GenericResourceData, hstLength: number) => {
44-
const history = ramHistory.get();
45-
history.push(rmUsg.percentage);
46-
if (history.length > hstLength) {
47-
history.shift();
48-
}
49-
ramHistory.set(history);
42+
const graphBinding = Variable.derive(
43+
[bind(showGraph), bind(ramUsage), historyLengthBinding()],
44+
(show, rmUsg: GenericResourceData, hstLength: number) => {
45+
if (!show) return '';
46+
47+
const history = ramHistory.get();
48+
history.push(rmUsg.percentage);
49+
if (history.length > hstLength) {
50+
history.shift();
51+
}
52+
ramHistory.set(history);
53+
54+
return history.map(getBarGraph).join('');
55+
}
56+
);
5057

51-
return history.map(getBarGraph).join('');
52-
})
53-
: Variable.derive([], () => '');
5458

5559
export const Ram = (): BarBoxChild => {
5660
const labelBinding = Variable.derive(

0 commit comments

Comments
 (0)