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 () { ...@@ -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.')) { 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) console.log('Overwriting', key)
files.set(key, resp[key]) files.set(key, resp[key])
updateFiles() refreshTabs()
} else { } else {
console.log('add to obj', obj, key) console.log('add to obj', obj, key)
obj[key] = files.get(key) obj[key] = files.get(key)
...@@ -296,7 +296,7 @@ var run = function () { ...@@ -296,7 +296,7 @@ var run = function () {
return false return false
}) })
editor.event.register('sessionSwitched', updateFiles) editor.event.register('sessionSwitched', refreshTabs)
function switchToFile (file) { function switchToFile (file) {
currentFile = file currentFile = file
...@@ -318,7 +318,7 @@ var run = function () { ...@@ -318,7 +318,7 @@ var run = function () {
switchToNextFile() switchToNextFile()
// Synchronise tab list with file names known to the editor // Synchronise tab list with file names known to the editor
function updateFiles () { function refreshTabs () {
var $filesEl = $('#files') var $filesEl = $('#files')
var fileNames = Object.keys(files.list()) var fileNames = Object.keys(files.list())
......
...@@ -18,19 +18,6 @@ function Storage () { ...@@ -18,19 +18,6 @@ function Storage () {
return true 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) { this.remove = function (name) {
window.localStorage.removeItem('sol:' + name) window.localStorage.removeItem('sol:' + name)
return true return true
...@@ -45,13 +32,17 @@ function Storage () { ...@@ -45,13 +32,17 @@ function Storage () {
return true return true
} }
this.loadFile = function (filename, content) { function safeKeys () {
if (this.exists(filename) && this.get(filename) !== content) { // NOTE: this is a workaround for some browsers
var count = '' return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined })
while (this.exists(filename + count)) count = count - 1 }
this.rename(filename, filename + count)
} this.keys = function () {
this.set(filename, content) 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 // 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