riot
Version:
Simple and elegant component-based UI library
28 lines (23 loc) • 1.08 kB
JavaScript
/* Riot v10.1.2, @license MIT */
import { COMPONENTS_IMPLEMENTATION_MAP } from '../dependencies/@riotjs/util/constants.js';
import { panic } from '../dependencies/@riotjs/util/misc.js';
import { createComponentFromWrapper } from '../core/create-component-from-wrapper.js';
/**
* Register a custom tag by name
* @param {string} name - component name
* @param {object} implementation - tag implementation
* @param {string} implementation.css - component css as string
* @param {TemplateChunk} implementation.template - component template chunk rendering function
* @param {object} implementation.exports - component default export
* @returns {Map} map containing all the components implementations
*/
function register(name, { css, template, exports: exports$1 }) {
if (COMPONENTS_IMPLEMENTATION_MAP.has(name))
panic(`The component "${name}" was already registered`);
COMPONENTS_IMPLEMENTATION_MAP.set(
name,
createComponentFromWrapper({ name, css, template, exports: exports$1 }),
);
return COMPONENTS_IMPLEMENTATION_MAP
}
export { register };