Skip to content

Commit

Permalink
perf: refactor custom component registration config
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjones243 committed Sep 26, 2024
1 parent 1d34523 commit 891f44a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
6 changes: 4 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@

<!-- Register the custom element for demo versioning purpose -->
<script type="module">
import { registerComponent } from '../index.js';
registerComponent('custom-badge');
import { AuroBadge } from '../src/auro-badge.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

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

<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-accordion@latest/dist/auro-accordion__bundled.js" type="module"></script>
Expand Down
6 changes: 4 additions & 2 deletions demo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,10 @@ 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 './node_modules/@aurodesignsystem/auro-badge';
registerComponent('custom-badge');
import { AuroBadge } from './src/auro-badge.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

RuntimeUtils.default.prototype.registerComponent('custom-badge', AuroBadge);
```

This will create a new custom element that you can use in your HTML that will function identically to the `auro-badge` element.
Expand Down
6 changes: 4 additions & 2 deletions docs/partials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ 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 './node_modules/@aurodesignsystem/auro-badge';
registerComponent('custom-badge');
import { AuroBadge } from './src/auro-badge.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

RuntimeUtils.default.prototype.registerComponent('custom-badge', AuroBadge);
```

This will create a new custom element that you can use in your HTML that will function identically to the `auro-badge` element.
Expand Down
16 changes: 2 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import { AuroBadge } from './src/auro-badge.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}
*/
export function registerComponent(name) {
// alias definition
if (!customElements.get(name)) {
customElements.define(name, class extends AuroBadge {});
}
}

// Example custom registration
// registerComponent('my-badge');
RuntimeUtils.default.prototype.registerComponent('custom-badge', AuroBadge);

0 comments on commit 891f44a

Please sign in to comment.