Commit b97b56f3 authored by Alex Beregszaszi's avatar Alex Beregszaszi Committed by GitHub

Merge pull request #426 from ethereum/cleanup

Cleanup storage.js
parents e064f0d7 9424342c
......@@ -127,7 +127,7 @@ var run = function () {
if (typeof resp[key] !== 'undefined' && obj[key] !== resp[key] && confirm('Overwrite "' + key + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.')) {
console.log('Overwriting', key)
files.set(key, resp[key])
updateFiles()
refreshTabs()
} else {
console.log('add to obj', obj, key)
obj[key] = files.get(key)
......@@ -296,7 +296,7 @@ var run = function () {
return false
})
editor.event.register('sessionSwitched', updateFiles)
editor.event.register('sessionSwitched', refreshTabs)
function switchToFile (file) {
currentFile = file
......@@ -318,7 +318,7 @@ var run = function () {
switchToNextFile()
// Synchronise tab list with file names known to the editor
function updateFiles () {
function refreshTabs () {
var $filesEl = $('#files')
var fileNames = Object.keys(files.list())
......
......@@ -18,19 +18,6 @@ function Storage () {
return true
}
function safeKeys () {
// NOTE: this is a workaround for some browsers
return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined })
}
this.keys = function () {
return safeKeys()
// filter any names not including sol:
.filter(function (item) { return item.indexOf('sol:', 0) === 0 })
// remove sol: from filename
.map(function (item) { return item.replace(/^sol:/, '') })
}
this.remove = function (name) {
window.localStorage.removeItem('sol:' + name)
return true
......@@ -45,13 +32,17 @@ function Storage () {
return true
}
this.loadFile = function (filename, content) {
if (this.exists(filename) && this.get(filename) !== content) {
var count = ''
while (this.exists(filename + count)) count = count - 1
this.rename(filename, filename + count)
}
this.set(filename, content)
function safeKeys () {
// NOTE: this is a workaround for some browsers
return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined })
}
this.keys = function () {
return safeKeys()
// filter any names not including sol:
.filter(function (item) { return item.indexOf('sol:', 0) === 0 })
// remove sol: from filename
.map(function (item) { return item.replace(/^sol:/, '') })
}
// on startup, upgrade the old storage layout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment