From 0dc9ff119591644003d83c6edb65082e77a28288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=B6hn?= Date: Sun, 10 Dec 2023 15:43:23 +0100 Subject: [PATCH] optimize code, use attribute getter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Höhn --- .../assets/definitions/blockly/blocks-color.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-color.js b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-color.js index d5250b1e9f..1cabe23db1 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-color.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-color.js @@ -5,7 +5,7 @@ import Blockly from 'blockly' import { javascriptGenerator } from 'blockly/javascript' -import { blockGetCheckedInputType } from '@/assets/definitions/blockly/utils.js'; +import { blockGetCheckedInputType } from '@/assets/definitions/blockly/utils.js' export default function (f7, isGraalJs) { /* @@ -69,17 +69,13 @@ export default function (f7, isGraalJs) { const inputType = blockGetCheckedInputType(block, 'item') let attributeName = block.getFieldValue('attributeName') - if (!isGraalJs) { - attributeName = attributeName.charAt(0).toLowerCase() + attributeName.slice(1) - let code = (inputType === 'oh_item') ? `items.getItem(${theItem}).rawState.${attributeName}` : `${theItem}.rawState.${attributeName}` - return [code, 0] + let code = '' + if (isGraalJs) { + code = (inputType === 'oh_item') ? `items.getItem(${theItem}).rawState.get${attributeName}()` : `${theItem}.rawState.get${attributeName}()` } else { - if (attributeName === 'Tags' || attributeName === 'GroupNames') { - return [`Java.from(${theItem}.getRawState().get${attributeName}())`, 0] - } else { - return [`${theItem}.getRawState().get${attributeName}()`, 0] - } + code = (inputType === 'oh_item') ? `itemRegistry.getItem(${theItem}).getRawState().get${attributeName}()` : `${theItem}.getRawState().get${attributeName}()` } + return [code, 0] } /*