UNPKG

@aws-amplify/interactions

Version:

Interactions category of aws-amplify

1 lines 2.24 kB
{"version":3,"file":"perContextCallbackRegistry.mjs","sources":["../../../src/utils/perContextCallbackRegistry.ts"],"sourcesContent":["/**\n * Creates a per-context callback registry. Keyed on the *resolved*\n * `AmplifyContext` object identity so a callback registered against one\n * context never fires for another (context isolation) — previously this was\n * a single process-global map keyed only by bot name, which leaked callbacks\n * across independent contexts.\n *\n * NOTE (re-configure semantics): `Amplify.configure()` publishes a NEW frozen\n * global context object on every call. A callback registered against the\n * global context before a re-configure is therefore keyed on the OLD context\n * object and will NOT be found after re-configure (the new global context is\n * a different object). Callers relying on the global context must re-register\n * their callback after reconfiguring; callers passing an explicit context keep\n * their callbacks for that context's lifetime. Using a `WeakMap` lets the\n * per-context records be garbage-collected once a context is unreferenced.\n */\nexport function createPerContextCallbackRegistry() {\n const callbacksByCtx = new WeakMap();\n return {\n set(ctx, name, callback) {\n const existing = callbacksByCtx.get(ctx);\n if (existing) {\n existing[name] = callback;\n }\n else {\n callbacksByCtx.set(ctx, { [name]: callback });\n }\n },\n get(ctx, name) {\n return callbacksByCtx.get(ctx)?.[name];\n },\n };\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gCAAgC,GAAG;AACnD,IAAI,MAAM,cAAc,GAAG,IAAI,OAAO,EAAE;AACxC,IAAI,OAAO;AACX,QAAQ,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE;AACjC,YAAY,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC;AACpD,YAAY,IAAI,QAAQ,EAAE;AAC1B,gBAAgB,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ;AACzC,YAAY;AACZ,iBAAiB;AACjB,gBAAgB,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,QAAQ,EAAE,CAAC;AAC7D,YAAY;AACZ,QAAQ,CAAC;AACT,QAAQ,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE;AACvB,YAAY,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AAClD,QAAQ,CAAC;AACT,KAAK;AACL;;;;"}