@webtides/element-js 1.2.3 → 1.2.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/BaseElement.js +21 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtides/element-js",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "module": "index.js",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -191,6 +191,18 @@ class BaseElement extends HTMLElement {
191
191
  }
192
192
  });
193
193
 
194
+ // release dom references
195
+ this.$refs = {};
196
+
197
+ // clear state
198
+ this._state = {};
199
+
200
+ // cancel pending updates
201
+ if (this._batchUpdate) {
202
+ cancelAnimationFrame(this._batchUpdate);
203
+ this._requestedUpdates = [];
204
+ }
205
+
194
206
  this.triggerHook('disconnected');
195
207
  }
196
208
 
@@ -297,16 +309,16 @@ class BaseElement extends HTMLElement {
297
309
  * Will trigger update() when a property was changed
298
310
  * @param {string} property
299
311
  * @param {any} value
300
- * @param {boolean} reflectAttribute
312
+ * @param {boolean} isAttribute
301
313
  */
302
- defineProperty(property, value, reflectAttribute = false) {
314
+ defineProperty(property, value, isAttribute = false) {
303
315
  if (this._state.hasOwnProperty(property)) {
304
316
  // property has already been defined as an attribute nothing to do here
305
317
  return;
306
318
  }
307
319
 
308
320
  // if property did not come from an attribute but has the option to reflect // enabled or custom fn
309
- if (!reflectAttribute && this._options.propertyOptions[property]?.reflect) {
321
+ if (!isAttribute && this._options.propertyOptions[property]?.reflect) {
310
322
  this.reflectProperty({ property: property, newValue: value });
311
323
  }
312
324
 
@@ -325,6 +337,11 @@ class BaseElement extends HTMLElement {
325
337
  this._state[property].subscribe(this);
326
338
  }
327
339
 
340
+ const descriptor = Object.getOwnPropertyDescriptor(this, property);
341
+ if (descriptor && descriptor.set && descriptor.get) {
342
+ // instance already has a defined, reactive ejs property
343
+ return;
344
+ }
328
345
  Object.defineProperty(this, property, {
329
346
  get: () => {
330
347
  return this._state[property];
@@ -341,7 +358,7 @@ class BaseElement extends HTMLElement {
341
358
  newValue.subscribe(this);
342
359
  }
343
360
 
344
- if (reflectAttribute || this._options.propertyOptions[property]?.reflect) {
361
+ if (isAttribute || this._options.propertyOptions[property]?.reflect) {
345
362
  this.reflectProperty({ property, newValue, newValueString });
346
363
  }
347
364