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 23, 2024
1 parent 1d70aff commit 56c98b7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
6 changes: 5 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
});
</script>
<script type="module" data-demo-script="true">
import { registerComponent } from '../index.js';
import { AuroButton } from './src/auro-button.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';

RuntimeUtils.default.prototype.registerComponent('custom-button', AuroButton);

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

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

RuntimeUtils.default.prototype.registerComponent('custom-button', AuroButton);
```

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

RuntimeUtils.default.prototype.registerComponent('custom-button', AuroButton);
```

This will create a new custom element that you can use in your HTML that will function identically to the `<auro-button>` element.
Expand Down
13 changes: 2 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import { AuroButton } from './src/auro-button.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 AuroButton {});
}
}
RuntimeUtils.default.prototype.registerComponent('custom-button', AuroButton);
6 changes: 3 additions & 3 deletions test/auro-button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/* eslint-disable no-undef */
import { fixture, html, expect, elementUpdated } from '@open-wc/testing';
import { AuroButton } from '../src/auro-button.js';
import { registerComponent } from '../index.js';
import * as RuntimeUtils from '@aurodesignsystem/auro-library/scripts/utils/runtimeUtils.mjs';
import '../index.js';

describe('auro-button', () => {
Expand All @@ -33,9 +33,9 @@ describe('auro-button', () => {
});

it('successfully registers custom component', async () => {
registerComponent('test-button');
RuntimeUtils.default.prototype.registerComponent('custom-button', AuroButton);

expect(typeof customElements.get('test-button')).to.equal(typeof AuroButton);
expect(typeof customElements.get('custom-button')).to.equal(typeof AuroButton);
});

it('tests setting autofocus', async () => {
Expand Down

0 comments on commit 56c98b7

Please sign in to comment.