rasti 4.2.0 → 4.2.1

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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <p align="center">
2
2
  <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.2.0/docs/logo-dark.svg">
4
- <img alt="Rasti.js" src="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.2.0/docs/logo.svg" height="120">
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.2.1/docs/logo-dark.svg">
4
+ <img alt="Rasti.js" src="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.2.1/docs/logo.svg" height="120">
5
5
  </picture>
6
6
  </p>
7
7
 
package/dist/rasti.js CHANGED
@@ -755,19 +755,28 @@
755
755
  Model.attributePrefix = '';
756
756
 
757
757
  /**
758
- * Define `key` on `target` as an own data property. Unlike an assignment, it does not go
759
- * through an accessor declared on the prototype, so it shadows a getter with no setter
760
- * instead of throwing.
761
- * @param {object} target Object to define the property on.
758
+ * Assign an option to `target`. A getter with no setter on the prototype would make the
759
+ * assignment throw, so in that case `key` is defined as an own data property, which
760
+ * shadows the getter. Any other accessor receives the value through its setter.
761
+ * @param {object} target Object to assign the option to.
762
762
  * @param {string} key Property name.
763
763
  * @param {any} value Property value.
764
764
  * @return {object} The target object.
765
765
  * @module
766
766
  * @private
767
767
  */
768
- const defineOwn = (target, key, value) => Object.defineProperty(target, key, {
769
- value, writable : true, enumerable : true, configurable : true
770
- });
768
+ const assignOption = (target, key, value) => {
769
+ try {
770
+ target[key] = value;
771
+ } catch (error) {
772
+ // Assigning to a getter with no setter throws a TypeError; anything else propagates.
773
+ if (!(error instanceof TypeError)) throw error;
774
+ Object.defineProperty(target, key, {
775
+ value, writable : true, enumerable : true, configurable : true
776
+ });
777
+ }
778
+ return target;
779
+ };
771
780
 
772
781
  /*
773
782
  * These option keys will be extended on the view instance.
@@ -838,11 +847,11 @@
838
847
  // Mutable array to store handlers to be called on destroy.
839
848
  this.destroyQueue = [];
840
849
  this.viewOptions = [];
841
- // Extend "this" with options, as own properties so an option overrides
842
- // a getter declared by a subclass instead of being assigned through it.
850
+ // Extend "this" with options. An option overrides a getter declared by a
851
+ // subclass even when the getter has no setter.
843
852
  viewOptions.forEach(key => {
844
853
  if (key in options) {
845
- defineOwn(this, key, options[key]);
854
+ assignOption(this, key, options[key]);
846
855
  this.viewOptions.push(key);
847
856
  }
848
857
  });
@@ -2424,11 +2433,11 @@
2424
2433
  constructor(options = {}) {
2425
2434
  super(...arguments);
2426
2435
  this.componentOptions = [];
2427
- // Extend "this" with options, as own properties so an option overrides
2428
- // a getter declared by a subclass instead of being assigned through it.
2436
+ // Extend "this" with options. An option overrides a getter declared by a
2437
+ // subclass even when the getter has no setter.
2429
2438
  componentOptions.forEach(key => {
2430
2439
  if (key in options) {
2431
- defineOwn(this, key, options[key]);
2440
+ assignOption(this, key, options[key]);
2432
2441
  this.componentOptions.push(key);
2433
2442
  }
2434
2443
  });