From fd1aabb4121f2decbcbe8de0c5be7227d2fb3bf4 Mon Sep 17 00:00:00 2001 From: 4eb0da <4eb0da@yandex-team.com> Date: Wed, 18 Sep 2024 13:01:53 +0300 Subject: [PATCH] isEmpty method for dict commit_hash:f3e964657a07b8c6de490b7a7f105e9a5a3f1214 --- client/web/divkit/src/expressions/funcs/dict.ts | 8 ++++++++ test_data/expression_test_data/methods_dict.json | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/client/web/divkit/src/expressions/funcs/dict.ts b/client/web/divkit/src/expressions/funcs/dict.ts index e664fa24e..901e780e9 100644 --- a/client/web/divkit/src/expressions/funcs/dict.ts +++ b/client/web/divkit/src/expressions/funcs/dict.ts @@ -101,6 +101,13 @@ function containsKey(_ext: EvalContext, dict: DictValue, key: StringValue): Bool }; } +function isEmpty(_ext: EvalContext, dict: DictValue): BooleanValue { + return { + type: BOOLEAN, + value: Object.keys(dict.value).length ? 0 : 1 + }; +} + export function registerDict(): void { const STRING_VARARG = { type: STRING, @@ -166,4 +173,5 @@ export function registerDict(): void { registerMethod('getArray', [DICT, STRING_VARARG], getDictArray); registerMethod('getDict', [DICT, STRING_VARARG], getDictDict); registerMethod('containsKey', [DICT, STRING], containsKey); + registerMethod('isEmpty', [DICT], isEmpty); } diff --git a/test_data/expression_test_data/methods_dict.json b/test_data/expression_test_data/methods_dict.json index 2cea664a3..149db349f 100644 --- a/test_data/expression_test_data/methods_dict.json +++ b/test_data/expression_test_data/methods_dict.json @@ -486,7 +486,8 @@ } ], "platforms": [ - "android" + "android", + "web" ] }, { @@ -503,7 +504,8 @@ } ], "platforms": [ - "android" + "android", + "web" ] } ]