Created
March 21, 2025 20:42
-
-
Save ilkkakuivanen/982e9d4b855399f278a9ce3daa2c1510 to your computer and use it in GitHub Desktop.
Singleton module
This file contains hidden or 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
let count: number | null = null; | |
function init(): void { | |
count = 0; | |
} | |
function increment(): void { | |
if (count) { | |
count++; | |
} | |
} | |
function decrement(): void { | |
if (count) { | |
count--; | |
} | |
} | |
function getCount(): number { | |
if (!count) { | |
throw new Error("Count has not been defined!"); | |
} | |
return count; | |
} | |
export { init, increment, decrement, getCount }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment