@mschop/alpine-web-components 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,6 @@ abstract class AlpineWebComponent extends HTMLElement {
24
24
  protected abstract template: string
25
25
  protected styles: () => string = () => ``
26
26
  protected attributeCasts: AttributeCasts = {};
27
- protected updatingAttribute = false;
28
27
  private alpineInitHandler = () => this.init()
29
28
 
30
29
  constructor() {
@@ -62,7 +61,9 @@ abstract class AlpineWebComponent extends HTMLElement {
62
61
  this.state.attributes = {};
63
62
  }
64
63
 
65
- if (oldValue === newValue) {
64
+ const castedNewValue = this.castFromAttribute(name, newValue);
65
+
66
+ if (oldValue === castedNewValue) {
66
67
  return;
67
68
  }
68
69
 
@@ -70,7 +71,7 @@ abstract class AlpineWebComponent extends HTMLElement {
70
71
  return;
71
72
  }
72
73
 
73
- this.state.attributes[name] = this.castFromAttribute(name, newValue);
74
+ this.state.attributes[name] = castedNewValue;
74
75
  }
75
76
 
76
77
  private loadTemplate() {
@@ -104,7 +105,17 @@ abstract class AlpineWebComponent extends HTMLElement {
104
105
  this.constructor.observedAttributes?.forEach((key: string) => {
105
106
  const value = this.getAttribute(key);
106
107
 
107
- this.state.attributes[key] = this.castFromAttribute(key, value)
108
+ if (value === null && this.state.attributes[key] !== undefined) {
109
+ const attribute = this.castToAttribute(
110
+ key,
111
+ this.castToAttribute(key, this.state.attributes[key])
112
+ );
113
+ if (attribute !== null) {
114
+ this.setAttribute(key, attribute)
115
+ }
116
+ } else {
117
+ this.state.attributes[key] = this.castFromAttribute(key, value)
118
+ }
108
119
  })
109
120
  }
110
121
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschop/alpine-web-components",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Use alpinejs with web components and shadow root",
5
5
  "main": "index.js",
6
6
  "scripts": {