kodadot/nft-gallery

View on GitHub
composables/useIdMap.ts

Summary

Maintainability
A
0 mins
Test Coverage
export default function<T>() {
  const map = ref(new Map<string, T>())

  const add = (initialValue: T) => {
    const id = window.crypto.randomUUID()
    map.value.set(id, initialValue as any)
    return id
  }

  const get = (id: string): T | undefined => map.value.get(id) as T | undefined

  return {
    add,
    get,
  }
}