UNPKG

@assistant-ui/react

Version:

Typescript/React library for AI Chat

1 lines 1.67 kB
{"version":3,"sources":["../../../../src/context/react/utils/ensureBinding.ts"],"sourcesContent":["type Bindable = {\n __internal_bindMethods?: () => void;\n __isBound?: boolean;\n};\nconst debugVerifyPrototype = (\n runtime: Record<string, unknown>,\n prototype: any,\n) => {\n const unboundMethods = Object.getOwnPropertyNames(prototype).filter(\n (methodStr) => {\n const descriptor = Object.getOwnPropertyDescriptor(prototype, methodStr);\n const isMethod = descriptor && typeof descriptor.value === \"function\";\n if (!isMethod) return false;\n\n const methodName = methodStr as keyof typeof runtime | \"constructor\";\n return (\n isMethod &&\n !methodName.startsWith(\"_\") &&\n methodName !== \"constructor\" &&\n prototype[methodName] === runtime[methodName]\n );\n },\n );\n\n if (unboundMethods.length > 0) {\n throw new Error(\n \"The following methods are not bound: \" + JSON.stringify(unboundMethods),\n );\n }\n\n const prototypePrototype = Object.getPrototypeOf(prototype);\n if (prototypePrototype && prototypePrototype !== Object.prototype) {\n debugVerifyPrototype(runtime, prototypePrototype);\n }\n};\nexport const ensureBinding = (r: unknown) => {\n const runtime = r as Bindable;\n if (runtime.__isBound) return;\n\n runtime.__internal_bindMethods?.();\n runtime.__isBound = true;\n\n // @ts-expect-error - strip this out in production build\n DEV: debugVerifyPrototype(runtime, Object.getPrototypeOf(runtime));\n};\n"],"mappings":";AAmCO,IAAM,gBAAgB,CAAC,MAAe;AAC3C,QAAM,UAAU;AAChB,MAAI,QAAQ,UAAW;AAEvB,UAAQ,yBAAyB;AACjC,UAAQ,YAAY;AAItB;","names":[]}