UNPKG

ember-source

Version:

A JavaScript framework for creating ambitious web applications

32 lines (29 loc) 1.16 kB
import { d as debugToString } from './debug-to-string-BsFOvUtQ.js'; import { isDevelopingApp } from '@embroider/macros'; const TEMPLATES = new WeakMap(); const getPrototypeOf = Reflect.getPrototypeOf; function setComponentTemplate(factory, obj) { if (isDevelopingApp() && !(obj !== null && (typeof obj === 'object' || typeof obj === 'function'))) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme throw new Error(`Cannot call \`setComponentTemplate\` on \`${debugToString(obj)}\``); } if (isDevelopingApp() && TEMPLATES.has(obj)) { throw new Error( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme `Cannot call \`setComponentTemplate\` multiple times on the same class (\`${debugToString(obj)}\`)`); } TEMPLATES.set(obj, factory); return obj; } function getComponentTemplate(obj) { let pointer = obj; while (pointer !== null) { let template = TEMPLATES.get(pointer); if (template !== undefined) { return template; } pointer = getPrototypeOf(pointer); } return undefined; } export { getComponentTemplate as g, setComponentTemplate as s };