Created
November 27, 2022 19:18
-
-
Save JCloudYu/cbee07716aadb6eb9a92e80b267601db to your computer and use it in GitHub Desktop.
A tiny volatile memory storage designed for better typing
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
import "process"; | |
declare global { | |
interface IVolatileStorage { | |
(key:'some-key'):{ | |
definition_1: Buffer; | |
definition_2: string; | |
} | |
} | |
} |
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
declare global { | |
interface IVolatileStorage { | |
<ReturnType extends {}=any>(key:string):ReturnType; | |
} | |
} | |
const DYN_DATA:Map<string, any> = new Map(); | |
const ACCESSOR:IVolatileStorage = function<ReturnType extends {}=any>(key:string='default'):ReturnType { | |
if ( !DYN_DATA.has(key) ) DYN_DATA.set(key, {}); | |
return DYN_DATA.get(key)! | |
}; | |
export default ACCESSOR; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment