From 861deadf2370a94dfef483b671bc77641c364186 Mon Sep 17 00:00:00 2001 From: Dave Hoover Date: Thu, 23 Jun 2016 17:38:52 -0500 Subject: [PATCH] Encapsulating 'Cache File Prefix' --- src/app/editor.js | 4 ++-- src/app/storage-handler.js | 2 +- src/app/utils.js | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/editor.js b/src/app/editor.js index e8dc95f906..c5892ff018 100644 --- a/src/app/editor.js +++ b/src/app/editor.js @@ -6,7 +6,7 @@ var ace = require('brace'); require('../mode-solidity.js'); function Editor (loadingFromGist) { - var SOL_CACHE_UNTITLED = utils.getCacheFilePrefix() + 'Untitled'; + var SOL_CACHE_UNTITLED = utils.fileKey('Untitled'); var SOL_CACHE_FILE = null; var editor = ace.edit('input'); @@ -70,7 +70,7 @@ function Editor (loadingFromGist) { function getFiles () { var files = []; for (var f in window.localStorage) { - if (f.indexOf(utils.getCacheFilePrefix(), 0) === 0) { + if (utils.isCachedFile(f)) { files.push(f); if (!sessions[f]) sessions[f] = newEditorSession(f); } diff --git a/src/app/storage-handler.js b/src/app/storage-handler.js index 15e6005254..9d566d67bf 100644 --- a/src/app/storage-handler.js +++ b/src/app/storage-handler.js @@ -35,7 +35,7 @@ function StorageHandler (updateFiles) { for (var y in window.localStorage) { console.log('checking', y); obj[y] = window.localStorage.getItem(y); - if (y.indexOf(utils.getCacheFilePrefix()) !== 0) { + if (!utils.isCachedFile(y)) { continue; } count++; diff --git a/src/app/utils.js b/src/app/utils.js index def28a8a19..78d58dc5b1 100644 --- a/src/app/utils.js +++ b/src/app/utils.js @@ -4,6 +4,10 @@ function getCacheFilePrefix () { return SOL_CACHE_FILE_PREFIX; } +function isCachedFile (name) { + return name.indexOf(getCacheFilePrefix(), 0) === 0; +} + function fileKey (name) { return getCacheFilePrefix() + name; } @@ -17,7 +21,7 @@ function errortype (message) { } module.exports = { - getCacheFilePrefix: getCacheFilePrefix, + isCachedFile: isCachedFile, fileKey: fileKey, fileNameFromKey: fileNameFromKey, errortype: errortype