Skip to content

Commit

Permalink
perf: refactor custom registration config
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjones243 authored and jason-capsule42 committed Sep 30, 2024
1 parent 72eab39 commit 78c786f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 4 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
</script>

<script type="module">
import { registerComponent } from '../index.js';
registerComponent('custom-menu');
import { AuroMenu } from '../src/auro-menu.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

RuntimeUtils.default.prototype.registerComponent('custom-menu', AuroMenu);
</script>

<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-accordion@latest/dist/auro-accordion__bundled.js" type="module"></script>
Expand Down
6 changes: 6 additions & 0 deletions demo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ There are two important parts of every Auro component. The <a href="https://deve

To protect from versioning conflicts with other instances of the component being loaded, it is recommended to use our `registerComponent(name)` method and pass in a unique name.

```js
import { AuroMenu } from '../src/auro-menu.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';
RuntimeUtils.default.prototype.registerComponent('custom-menu', AuroMenu);
```

<div class="exampleWrapper">
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../../apiExamples/custom.html) -->
<!-- The below content is automatically added from ./../../apiExamples/custom.html -->
Expand Down
6 changes: 6 additions & 0 deletions docs/partials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ There are two important parts of every Auro component. The <a href="https://deve

To protect from versioning conflicts with other instances of the component being loaded, it is recommended to use our `registerComponent(name)` method and pass in a unique name.

```js
import { AuroMenu } from '../src/auro-menu.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';
RuntimeUtils.default.prototype.registerComponent('custom-menu', AuroMenu);
```

<div class="exampleWrapper">
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../../apiExamples/custom.html) -->
<!-- AURO-GENERATED-CONTENT:END -->
Expand Down
15 changes: 2 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import { AuroMenu } from './src/auro-menu.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

/**
* Register Custom Element.
* @param {Object} name - Name to use for custom element.
* @returns {void}
*/
const registerComponent = (name = 'custom-menu') => {
// alias definition
if (!customElements.get(name)) {
customElements.define(name, class extends AuroMenu {});
}
}

export { registerComponent }
RuntimeUtils.default.prototype.registerComponent('auro-menu', AuroMenu);

0 comments on commit 78c786f

Please sign in to comment.