From 30b6f7f7793406cb467bd0c62a56d2c57e45a720 Mon Sep 17 00:00:00 2001 From: oitsjustjose Date: Tue, 29 Dec 2020 09:29:45 -0600 Subject: [PATCH] Optimize render cleanup --- frontend/src/components/view/ConfigRender.jsx | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/view/ConfigRender.jsx b/frontend/src/components/view/ConfigRender.jsx index 504c7bd..8f5fe5d 100644 --- a/frontend/src/components/view/ConfigRender.jsx +++ b/frontend/src/components/view/ConfigRender.jsx @@ -4,19 +4,25 @@ import { CSSTransition } from 'react-transition-group'; import GetConfig from '../../axios/Config/GetConfig'; const cleanJson = (json) => { - const formatted = { ...json.ores }; - if (formatted.oreBlocks) { - formatted.oreBlocks = formatted.oreBlocks.map((x) => [x.ore, x.chance]).flat(); - } - if (formatted.sampleBlocks) { - formatted.sampleBlocks = formatted.sampleBlocks.map((x) => [x.ore, x.chance]).flat(); - } + const formattedOres = []; - delete formatted.depType; + json.ores.forEach((deposit) => { + const clean = { ...deposit }; + + if (clean.oreBlocks) { + clean.oreBlocks = clean.oreBlocks.map((x) => [x.ore, x.chance]).flat(); + } + if (clean.sampleBlocks) { + clean.sampleBlocks = clean.sampleBlocks.map((x) => [x.ore, x.chance]).flat(); + } + delete clean.depType; + + formattedOres.push(clean); + }); return { - ores: formatted, - stones: json.stones, + ores: formattedOres, + stones: Array.from(json.stones), }; };