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 effeec5 commit c006e6f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
7 changes: 5 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
</script>

<script type="module" data-demo-script="true">
import { registerComponent } from '../index.js';
import { AuroCarousel } from '../src/auro-carousel.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

RuntimeUtils.default.prototype.registerComponent('custom-carousel', AuroCarousel);

import { initExamples } from './index.min.js';

registerComponent('custom-carousel');
initExamples();
</script>

Expand Down
6 changes: 4 additions & 2 deletions demo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,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-carousel';
registerComponent('custom-carousel');
import { AuroCarousel } from './src/auro-carousel.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

RuntimeUtils.default.prototype.registerComponent('custom-carousel', AuroCarousel);
```

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

RuntimeUtils.default.prototype.registerComponent('custom-carousel', AuroCarousel);
```

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

export { registerComponent }
RuntimeUtils.default.prototype.registerComponent('custom-carousel', AuroCarousel);

0 comments on commit c006e6f

Please sign in to comment.