Skip to content

Commit

Permalink
fix: define config DOM property accessors on the class prototype to m…
Browse files Browse the repository at this point in the history
…ake it compatible with framework bindings (#638)

Co-authored-by: nd0ut <[email protected]>
  • Loading branch information
nd0ut and nd0ut authored Apr 3, 2024
1 parent 9666f21 commit d47baf0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions blocks/Config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ class ConfigClass extends Block {

ConfigClass.bindAttributes(attrStateMapping);

/**
* Define getters and setters for all config keys on the Custom Element class prototype to make them checkable using
* `key in element` syntax. This is required for the frameworks DOM property bindings to work.
*/
for (const key of allConfigKeys) {
const localPropName = '__' + key;
Object.defineProperty(ConfigClass.prototype, key, {
/** @param {unknown} value */
set: function (value) {
this[localPropName] = value;
},
get: function () {
return this[localPropName];
},
});
}

/** @typedef {import('../../utils/mixinClass.js').MixinClass<typeof ConfigClass, import('../../types').ConfigType>} Config */

// This is workaround for jsdoc that allows us to export extended class type along with the class itself
Expand Down

0 comments on commit d47baf0

Please sign in to comment.