Skip to content

Commit 5655bef

Browse files
committed
refactor: don't use this.attributes
1 parent 5c7dbb5 commit 5655bef

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

packages/custom-element-signals/src/let-signal.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ export class LetSignal<T> extends HTMLElement {
3030

3131
signal: null | Signal<T> = null;
3232
_signalRegistry: SignalStoreInstance;
33-
34-
attributes!: NamedNodeMap & {
35-
name: { value: string };
36-
value: { value: string };
37-
save: { value: string };
38-
};
3933
constructor() {
4034
super();
4135
// if ((globalThis as any).signalRegistry) {
@@ -60,7 +54,7 @@ export class LetSignal<T> extends HTMLElement {
6054
createSignal(name: string, value?: any) {
6155
// Use the value attribute if it exists, otherwise use the innerHTML
6256
if (value === undefined) {
63-
const strValue = this.attributes?.["value"]?.value || this.innerHTML ||
57+
const strValue = this.getAttribute("value") || this.innerHTML ||
6458
"";
6559
value = parseAttributeValue(strValue);
6660
}
@@ -71,13 +65,13 @@ export class LetSignal<T> extends HTMLElement {
7165
// attributeChangedCallback fires before connectedCallback
7266
this.ready = true;
7367

74-
const name = this.attributes["name"]?.value;
68+
const name = this.getAttribute("name");
7569
if (!name) {
7670
throw new Error("let-signal must have a name attribute");
7771
}
7872
// console.log('connectedCallback', name)
7973

80-
const save = this.attributes["save"]?.value;
74+
const save = this.getAttribute("save");
8175
let value = undefined;
8276
// use handler registry
8377
if (save) {
@@ -131,8 +125,10 @@ export class LetSignal<T> extends HTMLElement {
131125
}
132126

133127
disconnectedCallback() {
134-
const name = this.attributes["name"].value;
135-
this._signalRegistry.delete(name);
128+
const name = this.getAttribute("name");
129+
if (name) {
130+
this._signalRegistry.delete(name);
131+
}
136132
this.ready = false;
137133
// (this as any)._signalRegistry = null;
138134
this.signal?.cleanUp();

packages/custom-element-signals/src/signal-html.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import { getTemplateContent } from "./utils/template-helpers";
66

77
export class SignalHtml extends HTMLElement {
88
static observedAttributes = ["name", "template-id"];
9-
attributes!: NamedNodeMap & {
10-
name: { value: string };
11-
"template-id"?: { value: string };
12-
};
13-
149
private signal: Signal<any> | null = null;
1510
private cleanUp: (() => void) | null = null;
1611
private template: string = '';
@@ -30,12 +25,12 @@ export class SignalHtml extends HTMLElement {
3025

3126
connectedCallback() {
3227
if (!this.isConnected) return;
33-
const name = this.attributes["name"]?.value;
28+
const name = this.getAttribute("name");
3429
if (!name) {
3530
throw new Error("signal-html must have a name attribute");
3631
}
3732

38-
const templateId = this.attributes["template-id"]?.value || generateTemplateId(this);
33+
const templateId = this.getAttribute("template-id") || generateTemplateId(this);
3934
const content = getTemplateContent(this, templateId, "signal-html");
4035

4136
if (content) {

packages/custom-element-signals/src/signal-text.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ export class SignalText extends HTMLElement {
88
"watch"
99
];
1010

11-
attributes!: NamedNodeMap & {
12-
name: { value: string };
13-
watch?: { value: string };
14-
};
15-
1611
signal: null | Signal<any> = null;
1712
_signalRegistry: Map<string, Signal<any>>;
1813
_watch: string | null = null;
@@ -29,8 +24,8 @@ export class SignalText extends HTMLElement {
2924

3025
connectedCallback() {
3126
this.mounted = true;
32-
const name = this.attributes["name"]?.value;
33-
this._watch = this.attributes["watch"]?.value ?? null;
27+
const name = this.getAttribute("name");
28+
this._watch = this.getAttribute("watch") ?? null;
3429
if (!name) {
3530
throw new Error("signal-text must have a name attribute");
3631
}

0 commit comments

Comments
 (0)