-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
535 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FileSource } from "./source" | ||
|
||
const statsSource = new FileSource("stats.json"); | ||
|
||
export type Stats = { [prop: string]: number|string }; | ||
let stats: Stats; | ||
|
||
const statsLoaded = statsSource.get().then((data) => { | ||
try { | ||
stats = JSON.parse(data); | ||
} catch (e) { | ||
stats = {}; | ||
} | ||
}); | ||
const saveStats = () => statsSource.set(JSON.stringify(stats)); | ||
|
||
export async function get(): Promise<Stats> { | ||
await statsLoaded; | ||
return stats; | ||
} | ||
|
||
export async function set(data: Stats): Promise<void> { | ||
await statsLoaded; | ||
Object.assign(stats, data); | ||
return saveStats(); | ||
} |
Oops, something went wrong.