import type { TokensType } from './interface'; type ComponentVar = Record; type Creator = (v: ComponentVar, t?: TokensType) => T; type KeyType = [ComponentVar, Creator]; const StyleMap: Map = new Map(); export const createStyle = ( componentVar: ComponentVar, creator: Creator, tokens?: TokensType ): T => { let myStyle: T; for (const [key, value] of StyleMap) { if (key[1] === creator) { if (key[0] === componentVar) { myStyle = value; } else { StyleMap.delete(key); } } } // @ts-ignore if (!myStyle) { myStyle = creator(componentVar, tokens); StyleMap.set([componentVar, creator], myStyle); } return myStyle; };