add presist

This commit is contained in:
discountry
2025-09-23 02:01:55 +08:00
parent 667ede7ca8
commit 1386455870
9 changed files with 319 additions and 80 deletions
+6 -3
View File
@@ -4,8 +4,8 @@ export interface TradeLogEntry {
detail: string;
}
export function createTradeLog(maxEntries: number) {
const entries: TradeLogEntry[] = [];
export function createTradeLog(maxEntries: number, seed: TradeLogEntry[] = []) {
const entries: TradeLogEntry[] = seed.slice(-maxEntries);
function push(type: string, detail: string) {
entries.push({ time: new Date().toLocaleString(), type, detail });
if (entries.length > maxEntries) {
@@ -15,5 +15,8 @@ export function createTradeLog(maxEntries: number) {
function all() {
return entries;
}
return { push, all };
function replace(next: TradeLogEntry[]) {
entries.splice(0, entries.length, ...next.slice(-maxEntries));
}
return { push, all, replace };
}