From 7edf5b5f1a2305c9285415da721be9d373b497ec Mon Sep 17 00:00:00 2001 From: Steven Evans Date: Thu, 5 Jul 2018 17:03:28 -0400 Subject: [PATCH] [refactor] Moved 'clearObject' to its own TS file --- src/Augmentations.js | 35 ++++++++++++++++++----------------- src/Bladeburner.js | 4 ++-- utils/HelperFunctions.js | 11 +---------- utils/helpers/clearObject.ts | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 utils/helpers/clearObject.ts diff --git a/src/Augmentations.js b/src/Augmentations.js index e4506ec98..44a361769 100644 --- a/src/Augmentations.js +++ b/src/Augmentations.js @@ -1,23 +1,24 @@ -import {BitNodeMultipliers} from "./BitNode"; -import {CONSTANTS} from "./Constants"; -import {Engine} from "./engine"; +import {BitNodeMultipliers} from "./BitNode"; +import {CONSTANTS} from "./Constants"; +import {Engine} from "./engine"; import {Factions, getNextNeurofluxLevel, - factionExists} from "./Faction"; -import {hasBladeburnerSF} from "./NetscriptFunctions"; -import {addWorkerScript} from "./NetscriptWorker"; -import {Player} from "./Player"; -import {prestigeAugmentation} from "./Prestige"; -import {saveObject} from "./SaveObject"; -import {Script, RunningScript} from "./Script"; -import {Server} from "./Server"; -import {SourceFiles} from "./SourceFile"; -import {dialogBoxCreate} from "../utils/DialogBox"; + factionExists} from "./Faction"; +import {hasBladeburnerSF} from "./NetscriptFunctions"; +import {addWorkerScript} from "./NetscriptWorker"; +import {Player} from "./Player"; +import {prestigeAugmentation} from "./Prestige"; +import {saveObject} from "./SaveObject"; +import {Script, RunningScript} from "./Script"; +import {Server} from "./Server"; +import {SourceFiles} from "./SourceFile"; +import {dialogBoxCreate} from "../utils/DialogBox"; import {createAccordionElement, - removeChildrenFromElement, clearObject} from "../utils/HelperFunctions"; + removeChildrenFromElement} from "../utils/HelperFunctions"; import {Reviver, Generic_toJSON, - Generic_fromJSON} from "../utils/JSONReviver"; -import {createElement} from "../utils/uiHelpers/createElement"; -import {isString} from "../utils/helpers/isString"; + Generic_fromJSON} from "../utils/JSONReviver"; +import {clearObject} from "../utils/helpers/clearObject"; +import {createElement} from "../utils/uiHelpers/createElement"; +import {isString} from "../utils/helpers/isString"; //Augmentations function Augmentation(params) { diff --git a/src/Bladeburner.js b/src/Bladeburner.js index 0c9115936..914bd66d7 100644 --- a/src/Bladeburner.js +++ b/src/Bladeburner.js @@ -11,14 +11,14 @@ import {KEY} from "./Terminal"; import {createProgressBarText} from "../utils/helpers/createProgressBarText"; import {dialogBoxCreate} from "../utils/DialogBox"; -import {clearObject, - removeChildrenFromElement, +import {removeChildrenFromElement, removeElement} from "../utils/HelperFunctions"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; import numeral from "numeral/min/numeral.min"; import {addOffset} from "../utils/helpers/addOffset"; import {appendLineBreaks} from "../utils/uiHelpers/appendLineBreaks"; +import {clearObject} from "../utils/helpers/clearObject"; import {createElement} from "../utils/uiHelpers/createElement"; import {createPopup} from "../utils/uiHelpers/createPopup"; import {exceptionAlert} from "../utils/helpers/exceptionAlert"; diff --git a/utils/HelperFunctions.js b/utils/HelperFunctions.js index 77fc83b06..c3a785438 100644 --- a/utils/HelperFunctions.js +++ b/utils/HelperFunctions.js @@ -1,14 +1,6 @@ //General helper functions import {isString} from "./helpers/isString"; -function clearObject(obj) { - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - delete obj[key]; - } - } -} - //Given an element by its Id(usually an 'a' element), removes all event listeners //from that element by cloning and replacing. Then returns the new cloned element function clearEventListeners(elemId) { @@ -80,8 +72,7 @@ function clearSelector(selector) { } } -export {clearObject, - clearEventListeners, +export {clearEventListeners, clearEventListenersEl, removeElement, createAccordionElement, diff --git a/utils/helpers/clearObject.ts b/utils/helpers/clearObject.ts new file mode 100644 index 000000000..fec858b20 --- /dev/null +++ b/utils/helpers/clearObject.ts @@ -0,0 +1,14 @@ +/** + * Clears defined properties from an object. + * Does not delete up the prototype chain. + * @deprecated Look into using `Map` or `Set` rather than manipulating properties on an Object. + * @param obj the object to clear all properties + */ +export function clearObject(obj: any) { + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + // tslint:disable-next-line:no-dynamic-delete + delete obj[key]; + } + } +}