-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from sverweij/feature/local-storage
Feature/local storage
- Loading branch information
Showing
15 changed files
with
210 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.9.76 | ||
0.9.78 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* global localStorage */ | ||
var store = require("../ui-control/store"); | ||
var assert = require("assert"); | ||
|
||
describe('store', function() { | ||
var lLanguage = "initial language"; | ||
var lSource = "initial source"; | ||
var lAutoRender = false; | ||
var lDebug = false; | ||
|
||
var lState = { | ||
getLanguage: function(){return "other language";}, | ||
setLanguage: function(pLanguage){lLanguage = pLanguage;}, | ||
getSource: function(){return "other source";}, | ||
setSource: function(pSource){lSource = pSource;}, | ||
getAutoRender: function(){return true;}, | ||
setAutoRender: function(pAutoRender){lAutoRender = pAutoRender;}, | ||
getDebug: function(){return true;}, | ||
setDebug: function(pDebug){lDebug = pDebug;} | ||
}; | ||
|
||
describe('#load and save with no localStorage available', function() { | ||
it('silently fail on load', function(){ | ||
store.load(lState); | ||
assert.equal(lLanguage, "initial language"); | ||
assert.equal(lSource, "initial source"); | ||
assert.equal(lAutoRender, false); | ||
assert.equal(lDebug, false); | ||
}); | ||
|
||
it('silently fail on save', function(){ | ||
store.save(lState); | ||
store.load(lState); | ||
assert.equal(lLanguage, "initial language"); | ||
assert.equal(lSource, "initial source"); | ||
assert.equal(lAutoRender, false); | ||
assert.equal(lDebug, false); | ||
}); | ||
}); | ||
|
||
describe('#load and save', function() { | ||
before(function(){ | ||
global.localStorage = new require('node-localstorage').LocalStorage('./throwmeaway'); | ||
localStorage.clear(); | ||
}); | ||
|
||
after(function(){ | ||
localStorage._deleteLocation(); | ||
}); | ||
|
||
it('leaves the state as is when localStorage has no item', function() { | ||
store.load(lState); | ||
assert.equal(lLanguage, "initial language"); | ||
assert.equal(lSource, "initial source"); | ||
assert.equal(lAutoRender, false); | ||
assert.equal(lDebug, false); | ||
}); | ||
|
||
it('saves the passed state', function(){ | ||
store.save(lState); | ||
store.load(lState); | ||
assert.equal(lLanguage, "other language"); | ||
assert.equal(lSource, "other source"); | ||
assert.equal(lAutoRender, true); | ||
assert.equal(lDebug, true); | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* jshint browser:true */ | ||
/* jshint node:true */ | ||
|
||
/* istanbul ignore else */ | ||
if ( typeof define !== 'function') { | ||
var define = require('amdefine')(module); | ||
} | ||
|
||
define([],function() { | ||
"use strict"; | ||
|
||
var STORAGE_KEY = "state"; | ||
|
||
function localStorageOK (){ | ||
return (typeof localStorage !== 'undefined'); | ||
} | ||
|
||
function getState(){ | ||
if (localStorageOK()){ | ||
try { | ||
return JSON.parse(localStorage.getItem(STORAGE_KEY)); | ||
} catch (e){ | ||
// silently swallow | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
function save(pState){ | ||
if (localStorageOK()){ | ||
localStorage.setItem(STORAGE_KEY, | ||
JSON.stringify({ | ||
language: pState.getLanguage(), | ||
source: pState.getSource(), | ||
autorender: pState.getAutoRender(), | ||
debug: pState.getDebug() | ||
}) | ||
); | ||
} | ||
} | ||
|
||
function load(pState){ | ||
var lState = getState(); | ||
if (lState){ | ||
pState.setLanguage(lState.language); | ||
pState.setSource(lState.source); | ||
pState.setAutoRender(lState.autorender); | ||
pState.setDebug(lState.debug); | ||
} | ||
} | ||
|
||
return { | ||
save: save, | ||
load: load | ||
}; | ||
}); | ||
/* | ||
This file is part of mscgen_js. | ||
mscgen_js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
mscgen_js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with mscgen_js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ |
Oops, something went wrong.