[refactor] Moved 'clearObject' to its own TS file

This commit is contained in:
Steven Evans 2018-07-05 17:03:28 -04:00
parent bcc6d39b10
commit 7edf5b5f1a
4 changed files with 35 additions and 29 deletions

@ -13,9 +13,10 @@ import {Server} from "./Server";
import {SourceFiles} from "./SourceFile"; import {SourceFiles} from "./SourceFile";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {createAccordionElement, import {createAccordionElement,
removeChildrenFromElement, clearObject} from "../utils/HelperFunctions"; removeChildrenFromElement} from "../utils/HelperFunctions";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import {clearObject} from "../utils/helpers/clearObject";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {isString} from "../utils/helpers/isString"; import {isString} from "../utils/helpers/isString";

@ -11,14 +11,14 @@ import {KEY} from "./Terminal";
import {createProgressBarText} from "../utils/helpers/createProgressBarText"; import {createProgressBarText} from "../utils/helpers/createProgressBarText";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {clearObject, import {removeChildrenFromElement,
removeChildrenFromElement,
removeElement} from "../utils/HelperFunctions"; removeElement} from "../utils/HelperFunctions";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import numeral from "numeral/min/numeral.min"; import numeral from "numeral/min/numeral.min";
import {addOffset} from "../utils/helpers/addOffset"; import {addOffset} from "../utils/helpers/addOffset";
import {appendLineBreaks} from "../utils/uiHelpers/appendLineBreaks"; import {appendLineBreaks} from "../utils/uiHelpers/appendLineBreaks";
import {clearObject} from "../utils/helpers/clearObject";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup"; import {createPopup} from "../utils/uiHelpers/createPopup";
import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {exceptionAlert} from "../utils/helpers/exceptionAlert";

@ -1,14 +1,6 @@
//General helper functions //General helper functions
import {isString} from "./helpers/isString"; 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 //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 //from that element by cloning and replacing. Then returns the new cloned element
function clearEventListeners(elemId) { function clearEventListeners(elemId) {
@ -80,8 +72,7 @@ function clearSelector(selector) {
} }
} }
export {clearObject, export {clearEventListeners,
clearEventListeners,
clearEventListenersEl, clearEventListenersEl,
removeElement, removeElement,
createAccordionElement, createAccordionElement,

@ -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];
}
}
}