Last active
November 24, 2023 04:09
-
-
Save TheLucifurry/64df4c7a09b00106c24141cd6b131afd to your computer and use it in GitHub Desktop.
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
| function useRefsMap<K extends string | number | symbol, V>() { | |
| const mapRefs = new Map<K, Ref<V | undefined>>() | |
| return { | |
| ...mapRefs, | |
| set(key: K, value: V) { | |
| if (mapRefs.has(key)) { | |
| const r = mapRefs.get(key)! | |
| r.value = value | |
| } else { | |
| mapRefs.set(key, ref(value) as Ref<V>) | |
| } | |
| }, | |
| get(key: K) { | |
| if (mapRefs.has(key)) | |
| return mapRefs.get(key)! | |
| const newRef = ref(undefined) | |
| mapRefs.set(key, newRef) | |
| return newRef | |
| }, | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment