Skip to content

Commit d47baf0

Browse files
authored
fix: define config DOM property accessors on the class prototype to make it compatible with framework bindings (#638)
Co-authored-by: nd0ut <[email protected]>
1 parent 9666f21 commit d47baf0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Diff for: blocks/Config/Config.js

+17
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ class ConfigClass extends Block {
139139

140140
ConfigClass.bindAttributes(attrStateMapping);
141141

142+
/**
143+
* Define getters and setters for all config keys on the Custom Element class prototype to make them checkable using
144+
* `key in element` syntax. This is required for the frameworks DOM property bindings to work.
145+
*/
146+
for (const key of allConfigKeys) {
147+
const localPropName = '__' + key;
148+
Object.defineProperty(ConfigClass.prototype, key, {
149+
/** @param {unknown} value */
150+
set: function (value) {
151+
this[localPropName] = value;
152+
},
153+
get: function () {
154+
return this[localPropName];
155+
},
156+
});
157+
}
158+
142159
/** @typedef {import('../../utils/mixinClass.js').MixinClass<typeof ConfigClass, import('../../types').ConfigType>} Config */
143160

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

0 commit comments

Comments
 (0)