Skip to content

Commit

Permalink
feat(core): define is not responsible to check if element is already …
Browse files Browse the repository at this point in the history
…registered
  • Loading branch information
lorenzofox3 committed Mar 8, 2024
1 parent 8c91f74 commit 6fa85ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
6 changes: 5 additions & 1 deletion apps/restaurant-cashier/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export const createApp = ({ router }) => {
});
};

const _define = (tag, comp, ...rest) => define(tag, withRoot(comp), ...rest);
const _define = (tag, comp, ...rest) => {
if (!customElements.get(tag)) {
define(tag, withRoot(comp), ...rest);
}
};

_define('ui-icon', UIIcon, {
shadow: { mode: 'open' },
Expand Down
23 changes: 10 additions & 13 deletions packages/core/src/define.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { component } from './component.js';

export const define = (tag, coroutine, opts = {}) => {
if (!customElements.get(tag)) {
customElements.define(
tag,
component(coroutine, {
observedAttributes: opts.observedAttributes,
Klass: classElementMap[opts?.extends] ?? HTMLElement,
...opts,
}),
opts,
);
}
};
export const define = (tag, coroutine, opts = {}) =>
customElements.define(
tag,
component(coroutine, {
observedAttributes: opts.observedAttributes,
Klass: classElementMap[opts?.extends] ?? HTMLElement,
...opts,
}),
opts,
);

const classElementMap = {
label: HTMLLabelElement,
Expand Down

0 comments on commit 6fa85ee

Please sign in to comment.