react-devbelt 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/install-plugins.ts"],"sourcesContent":["import type { DevBeltPlugin } from \"./plugin\";\n\ntype Installed = { cleanup: () => void; refs: number };\n\nconst KEY = \"__devbeltInstalled\";\n\nfunction registry(): Map<string, Installed> {\n const host = window as unknown as Record<string, Map<string, Installed>>;\n return (host[KEY] ??= new Map());\n}\n\n/**\n * Runs each plugin's `install` once per frame, however many times this is\n * called (a strict-mode remount, `installDevBelt` plus `<DevBelt />`).\n * The returned function lets go of this caller's hold; a plugin is cleaned up\n * when nobody holds it.\n */\nexport function installPlugins(plugins: readonly DevBeltPlugin[]): () => void {\n if (typeof window === \"undefined\") return () => {};\n const ids = new Set<string>();\n for (const { id } of plugins) {\n if (ids.has(id)) {\n throw new Error(\n `devbelt: two plugins share the id \"${id}\". Plugin ids must be unique.`,\n );\n }\n ids.add(id);\n }\n const installed = registry();\n const held: string[] = [];\n\n for (const plugin of plugins) {\n const existing = installed.get(plugin.id);\n if (existing) {\n existing.refs++;\n } else {\n let cleanup: () => void = () => {};\n try {\n cleanup = plugin.install?.() ?? (() => {});\n } catch (error) {\n // one broken plugin must not take the others down\n console.warn(`devbelt: plugin \"${plugin.id}\" failed to install`, error);\n }\n installed.set(plugin.id, { cleanup, refs: 1 });\n }\n held.push(plugin.id);\n }\n\n let released = false;\n return () => {\n if (released) return;\n released = true;\n for (const id of held) {\n const entry = installed.get(id);\n if (entry && --entry.refs <= 0) {\n entry.cleanup();\n installed.delete(id);\n }\n }\n };\n}\n"],"mappings":";;;AAIA,IAAM,MAAM;AAEZ,SAAS,WAAmC;AAC1C,QAAM,OAAO;AACb,SAAQ,KAAK,GAAG,MAAM,oBAAI,IAAI;AAChC;AAQO,SAAS,eAAe,SAA+C;AAC5E,MAAI,OAAO,WAAW,YAAa,QAAO,MAAM;AAAA,EAAC;AACjD,QAAM,MAAM,oBAAI,IAAY;AAC5B,aAAW,EAAE,GAAG,KAAK,SAAS;AAC5B,QAAI,IAAI,IAAI,EAAE,GAAG;AACf,YAAM,IAAI;AAAA,QACR,sCAAsC,EAAE;AAAA,MAC1C;AAAA,IACF;AACA,QAAI,IAAI,EAAE;AAAA,EACZ;AACA,QAAM,YAAY,SAAS;AAC3B,QAAM,OAAiB,CAAC;AAExB,aAAW,UAAU,SAAS;AAC5B,UAAM,WAAW,UAAU,IAAI,OAAO,EAAE;AACxC,QAAI,UAAU;AACZ,eAAS;AAAA,IACX,OAAO;AACL,UAAI,UAAsB,MAAM;AAAA,MAAC;AACjC,UAAI;AACF,kBAAU,OAAO,UAAU,MAAM,MAAM;AAAA,QAAC;AAAA,MAC1C,SAAS,OAAO;AAEd,gBAAQ,KAAK,oBAAoB,OAAO,EAAE,uBAAuB,KAAK;AAAA,MACxE;AACA,gBAAU,IAAI,OAAO,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;AAAA,IAC/C;AACA,SAAK,KAAK,OAAO,EAAE;AAAA,EACrB;AAEA,MAAI,WAAW;AACf,SAAO,MAAM;AACX,QAAI,SAAU;AACd,eAAW;AACX,eAAW,MAAM,MAAM;AACrB,YAAM,QAAQ,UAAU,IAAI,EAAE;AAC9B,UAAI,SAAS,EAAE,MAAM,QAAQ,GAAG;AAC9B,cAAM,QAAQ;AACd,kBAAU,OAAO,EAAE;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}