mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
added methods:
isSupported() getEditsStoreSizeBytes() getLocalStorageSizeBytes()
This commit is contained in:
parent
6c6fb11086
commit
d29dfb8b85
@ -1,6 +1,6 @@
|
||||
"use strict"
|
||||
|
||||
define(["esri/graphic"],function(Graphic)
|
||||
define(["esri/graphic"], function(Graphic)
|
||||
{
|
||||
/* private consts */
|
||||
var EDITS_QUEUE_KEY = "esriEditsQueue";
|
||||
@ -19,6 +19,19 @@ define(["esri/graphic"],function(Graphic)
|
||||
UPDATE: "update",
|
||||
DELETE:"delete",
|
||||
|
||||
isSupported: function()
|
||||
{
|
||||
// http://stackoverflow.com/questions/11214404/how-to-detect-if-browser-supports-html5-local-storage
|
||||
var mod = 'esriLocalStorageTest';
|
||||
try {
|
||||
window.localStorage.setItem(mod, mod);
|
||||
window.localStorage.removeItem(mod);
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
pushEdit: function(operation,layer,graphic)
|
||||
{
|
||||
var edit = {
|
||||
@ -126,6 +139,24 @@ define(["esri/graphic"],function(Graphic)
|
||||
return editToRedo;
|
||||
},
|
||||
|
||||
getEditsStoreSizeBytes: function()
|
||||
{
|
||||
return window.localStorage.getItem(EDITS_QUEUE_KEY).length +
|
||||
window.localStorage.getItem(REDO_STACK_KEY).length;
|
||||
|
||||
},
|
||||
|
||||
getLocalStorageSizeBytes: function()
|
||||
{
|
||||
var bytes = 0;
|
||||
for( var key in window.localStorage )
|
||||
{
|
||||
var value = window.localStorage.getItem(key);
|
||||
bytes += value.length;
|
||||
}
|
||||
return bytes;
|
||||
},
|
||||
|
||||
//
|
||||
// internal methods
|
||||
//
|
||||
|
||||
@ -190,6 +190,14 @@ describe("Internal Methods", function()
|
||||
|
||||
describe("Public Interface", function()
|
||||
{
|
||||
describe("Support detection", function()
|
||||
{
|
||||
it("detect local storage support", function()
|
||||
{
|
||||
expect(g_editsStore.isSupported()).toBeTruthy();
|
||||
})
|
||||
});
|
||||
|
||||
describe("Edit queue management", function()
|
||||
{
|
||||
describe("Normal edits", function()
|
||||
@ -420,6 +428,23 @@ describe("Public Interface", function()
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Local Storage size", function()
|
||||
{
|
||||
var usedBytes, totalBytes;
|
||||
|
||||
it("report edit store size", function()
|
||||
{
|
||||
usedBytes = g_editsStore.getEditsStoreSizeBytes();
|
||||
expect(usedBytes).toBe(678);
|
||||
});
|
||||
|
||||
it("report total local storage size", function()
|
||||
{
|
||||
totalBytes = g_editsStore.getLocalStorageSizeBytes();
|
||||
expect(usedBytes).not.toBeGreaterThan(totalBytes);
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
describe("Reset store", function()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user