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 27, 2024
1 parent d8c3f71 commit 147af17
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
5 changes: 3 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
</script>
<script type="module" data-demo-script="true" src="../index.js"></script>
<script type="module">
import { registerComponent } from '../index.js';
import { AuroSkeleton } from '../src/auro-skeleton.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

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

<!-- If additional elements are needed for the demo, add them here. -->
Expand Down
6 changes: 4 additions & 2 deletions demo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,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-skeleton';
registerComponent('custom-skeleton');
import { AuroSkeleton } from './src/auro-skeleton.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

RuntimeUtils.default.prototype.registerComponent('custom-skeleton', AuroSkeleton);
```

This will create a new custom element that you can use in your HTML that will function identically to the `<auro-skeleton>` 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 @@ -61,8 +61,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-skeleton';
registerComponent('custom-skeleton');
import { AuroSkeleton } from './src/auro-skeleton.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

RuntimeUtils.default.prototype.registerComponent('custom-skeleton', AuroSkeleton);
```

This will create a new custom element that you can use in your HTML that will function identically to the `<auro-skeleton>` element.
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 { AuroSkeleton } from './src/auro-skeleton.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-skeleton') => {
// alias definition
if (!customElements.get(name)) {
customElements.define(name, class extends AuroSkeleton {});
}
}

export { registerComponent }
RuntimeUtils.default.prototype.registerComponent('custom-skeleton', AuroSkeleton);

0 comments on commit 147af17

Please sign in to comment.