From 54411e4b429259afd0b895342d3ab6bca745481c Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 12 Jun 2018 22:02:46 -0400 Subject: [PATCH] separating the functions into a lib file --- setup/moduleLib.js | 98 ++++++++++++++++++++++++++++++ setup/renderer.js | 98 ++---------------------------- setup/{moduleSetup.js => tools.js} | 0 3 files changed, 102 insertions(+), 94 deletions(-) create mode 100644 setup/moduleLib.js rename setup/{moduleSetup.js => tools.js} (100%) diff --git a/setup/moduleLib.js b/setup/moduleLib.js new file mode 100644 index 0000000..cd6659a --- /dev/null +++ b/setup/moduleLib.js @@ -0,0 +1,98 @@ +const modLib = (function() { + return { + + setModules: function(modType,modName){ + appState[modType] = modName; + return appState; + }, + storeModules: function(appState){ + localStorage.setItem("app", JSON.stringify(appState)); + }, + getModuleTypes: function(modules){ + return Object.keys(modules) + }, + getModules: function(){ + return JSON.parse(localStorage.getItem("app")); + }, + updateModule: function(appState){ + let allMods = modLib.getModules(); + allMods[appState.modType].forEach(function(mod, index){ + if(mod.name === appState.name){ + allMods[appState.modType][index] = appState; + } + }) + localStorage.setItem("app", JSON.stringify(allMods)); + }, + getModuleByName: function(modName){ + let mods = JSON.parse(localStorage.getItem("app")), newMods = []; + for(modType in mods){ + newMods.push(modLib.getModulesByType(modType).filter(function(mod){ + return mod.name == modName; + })) + } + return newMods[0].concat(newMods[1])[0]; + }, + + // Returns an array of Modules + getModulesByType: function(moduleType){ + let appState = JSON.parse(localStorage.getItem("app")); + return appState[moduleType]; + }, + getDevDirs: function(){ + let fullPath = path.join(__dirname, `../dev`); + fs.readdir(fullPath, function(err, item) { + console.log(item) + }); + }, + generateListItems: function(modType){ + $(`

${modType}

`).appendTo( $("#module-list-container")); + $(`