Skip to content

Commit c2212c1

Browse files
committed
refactor
1 parent 6d60a7e commit c2212c1

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

packages/uui-icon-registry/lib/uui-icon-registry.element.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { UUIIconRegistry } from './UUIIconRegistry';
1111
export class UUIIconRegistryElement extends LitElement {
1212
/**
1313
* Provide a Dictionary/Record/Object where key is the icon name and the value is the SVGs to define in the icon registry.
14+
* @type {Record<string, string>}
15+
* @default {}
1416
*/
1517
@property({ attribute: false })
1618
private _icons: Record<string, string> = {};
@@ -20,38 +22,28 @@ export class UUIIconRegistryElement extends LitElement {
2022
set icons(icons) {
2123
this._icons = icons;
2224
if (this._registry) {
23-
this.defineIconsInRegistry();
25+
Object.entries(this._icons).forEach(([key, value]) =>
26+
this._registry.defineIcon(key, value)
27+
);
2428
}
2529
}
2630

27-
private defineIconsInRegistry() {
28-
Object.entries(this._icons).forEach(([key, value]) =>
29-
this._registry.defineIcon(key, value)
30-
);
31-
}
32-
3331
private _registry: UUIIconRegistry = new UUIIconRegistry();
3432

3533
public get registry(): UUIIconRegistry {
3634
return this._registry;
3735
}
3836
public set registry(newRegistry: UUIIconRegistry) {
39-
if (this.shadowRoot) {
40-
if (this.registry) {
41-
this.registry.detach(this);
42-
}
43-
newRegistry.attach(this);
37+
if (this.registry) {
38+
this.registry.detach(this);
4439
}
40+
newRegistry.attach(this);
4541
this._registry = newRegistry;
4642
}
4743

48-
connectedCallback(): void {
49-
super.connectedCallback();
50-
this.registry.attach(this);
51-
}
52-
disconnectedCallback(): void {
53-
super.disconnectedCallback();
54-
this.registry.detach(this);
44+
constructor() {
45+
super();
46+
this._registry.attach(this);
5547
}
5648

5749
render() {

0 commit comments

Comments
 (0)