@tldraw/utils
Version:
tldraw infinite canvas SDK (private utilities).
8 lines (7 loc) • 2.19 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/lib/warn.ts"],
"sourcesContent": ["const usedWarnings = new Set<string>()\n\n/**\n * Issues a deprecation warning for deprecated getter properties, advising users to use\n * the equivalent getter method instead. The warning is shown only once per property name.\n *\n * @param name - The name of the deprecated property (e.g., 'viewport')\n *\n * @example\n * ```ts\n * // Inside a class with deprecated property access\n * get viewport() {\n * warnDeprecatedGetter('viewport')\n * return this.getViewport()\n * }\n *\n * // Usage will show: \"[tldraw] Using 'viewport' is deprecated and will be removed...\"\n * // But only the first time it's accessed\n * ```\n *\n * @internal\n */\nexport function warnDeprecatedGetter(name: string) {\n\twarnOnce(\n\t\t`Using '${name}' is deprecated and will be removed in the near future. Please refactor to use 'get${name[0].toLocaleUpperCase()}${name.slice(\n\t\t\t1\n\t\t)}' instead.`\n\t)\n}\n\n/**\n * Issues a warning message to the console, but only once per unique message.\n * Subsequent calls with the same message are ignored, preventing console spam.\n * All messages are prefixed with \"[tldraw]\".\n *\n * @param message - The warning message to display\n *\n * @example\n * ```ts\n * // Warn about deprecated usage\n * function oldFunction() {\n * warnOnce('oldFunction is deprecated, use newFunction instead')\n * // Continue with implementation...\n * }\n *\n * // First call logs: \"[tldraw] oldFunction is deprecated, use newFunction instead\"\n * oldFunction() // Shows warning\n * oldFunction() // No warning (already shown)\n * oldFunction() // No warning (already shown)\n * ```\n *\n * @internal\n */\nexport function warnOnce(message: string) {\n\tif (usedWarnings.has(message)) return\n\n\tusedWarnings.add(message)\n\tconsole.warn(`[tldraw] ${message}`)\n}\n"],
"mappings": "AAAA,MAAM,eAAe,oBAAI,IAAY;AAsB9B,SAAS,qBAAqB,MAAc;AAClD;AAAA,IACC,UAAU,IAAI,sFAAsF,KAAK,CAAC,EAAE,kBAAkB,CAAC,GAAG,KAAK;AAAA,MACtI;AAAA,IACD,CAAC;AAAA,EACF;AACD;AAyBO,SAAS,SAAS,SAAiB;AACzC,MAAI,aAAa,IAAI,OAAO,EAAG;AAE/B,eAAa,IAAI,OAAO;AACxB,UAAQ,KAAK,YAAY,OAAO,EAAE;AACnC;",
"names": []
}