From 8759c7704233a57a1d1f858bc5a6448c9751feed Mon Sep 17 00:00:00 2001 From: Eric NGUYEN Date: Tue, 16 Aug 2022 11:43:31 +0200 Subject: [PATCH] Refactor PropertiesOperations duplicate --- src/Components/Editor/PropertiesOperations.ts | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/Components/Editor/PropertiesOperations.ts b/src/Components/Editor/PropertiesOperations.ts index cccc363..92e707d 100644 --- a/src/Components/Editor/PropertiesOperations.ts +++ b/src/Components/Editor/PropertiesOperations.ts @@ -97,32 +97,25 @@ export function OnPropertiesSubmit( // Assign container properties for (const property in container.properties) { - const input = (event.target as HTMLFormElement).querySelector(`#${property}`); - if (input instanceof HTMLInputElement) { - (container.properties as any)[property] = input.value; + const input: HTMLInputElement | null = (event.target as HTMLFormElement).querySelector(`#${property}`); - if (INPUT_TYPES[property] === 'number') { - (container.properties as any)[property] = Number(input.value); - continue; - } + if (input === null) { + continue; + } - (container.properties as any)[property] = input.value; + (container.properties as any)[property] = input.value; + if (INPUT_TYPES[property] === 'number') { + (container.properties as any)[property] = Number(input.value); } } // Assign cssproperties for (const styleProperty in container.properties.style) { - const input = (event.target as HTMLFormElement).querySelector(`#${styleProperty}`); - if (input instanceof HTMLInputElement) { - (container.properties.style as any)[styleProperty] = input.value; - - if (INPUT_TYPES[styleProperty] === 'number') { - (container.properties.style as any)[styleProperty] = Number(input.value); - continue; - } - - (container.properties.style as any)[styleProperty] = input.value; + const input: HTMLInputElement | null = (event.target as HTMLFormElement).querySelector(`#${styleProperty}`); + if (input === null) { + continue; } + (container.properties.style as any)[styleProperty] = input.value; } if (container.properties.isRigidBody) {