From d47baf0bb91355cd30411b5f2a8910606d5a1fe0 Mon Sep 17 00:00:00 2001 From: Aleksandr Grenishin Date: Wed, 3 Apr 2024 20:08:53 +0300 Subject: [PATCH] fix: define config DOM property accessors on the class prototype to make it compatible with framework bindings (#638) Co-authored-by: nd0ut --- blocks/Config/Config.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/blocks/Config/Config.js b/blocks/Config/Config.js index e4387c203..4ddc6ae95 100644 --- a/blocks/Config/Config.js +++ b/blocks/Config/Config.js @@ -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} Config */ // This is workaround for jsdoc that allows us to export extended class type along with the class itself