Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>jylauril is on the right track, I think.</p> <p>I've been playing with delays, and noticing some odd behavior.</p> <p>As far as I can tell, it seems like if you touch localStorage at all before ALL JavaScript has completed execution, including JS doing setTimeout, localStorage will appear blank for that pageview. For example:</p> <pre><code>$(window).load(function () { console.log("Waiting 10000ms", new Date()); setTimeout(setDeckSelect, 10000); }); </code></pre> <p>Firebug's console:</p> <pre><code>Waiting 10000ms Date {Thu Dec 13 2012 10:35:48 GMT-0500 (Eastern Standard Time)} exec.js (line 191) getDecks Date {Thu Dec 13 2012 10:35:58 GMT-0500 (Eastern Standard Time)} vault.js (line 23) &gt;&gt;&gt; localStorage 0 items in Storage </code></pre> <p>I thought I might be on to something, but my theories so far have proven wrong. One weird thing I've noticed, though. Regardless of how long I wait, if I try to look up decks first, it will fail and local storage will be empty:</p> <pre><code>&gt;&gt;&gt; vault.getDecks() [] &gt;&gt;&gt; localStorage 0 items in Storage </code></pre> <p>But if I do those in the opposite order...</p> <pre><code>&gt;&gt;&gt; localStorage 8 items in Storage deck:dfs= "{"identity":"MakingNews","cards":{}}", deck:ngrngfrn= "{"identity":"BuildingaBetterWorld","cards":{}}", deck:sdfgshsh= "{"identity":"MakingNews","cards":{}}", deck:sdfgdgdfg= "{"identity":"MakingNews","cards":{}}", deck:dfgdfgas= "{"identity":"EngineeringtheFuture","cards":{}}", deck:sdfsga= "{"identity":"MakingNews","cards":{}}", deck:gdgd= "{"identity":"MakingNews","cards":{}}", deck:gfsdfgsdfg= "{"identity":"BuildingaBetterWorld","cards":{}}" &gt;&gt;&gt; vault.getDecks() [Object { name= "dfgdfgas", key= "deck:dfgdfgas"}, Object { name= "dfs", key= "deck:dfs"}, Object { name= "gdgd", key= "deck:gdgd"}, Object { name= "gfsdfgsdfg", key= "deck:gfsdfgsdfg"}, Object { name= "ngrngfrn", key= "deck:ngrngfrn"}, Object { name= "sdfgdgdfg", key= "deck:sdfgdgdfg"}, Object { name= "sdfgshsh", key= "deck:sdfgshsh"}, Object { name= "sdfsga", key= "deck:sdfsga"}] </code></pre> <p>If I log localStorage in the function, it works as well:</p> <pre><code>vault.getDecks = function () { console.log(localStorage); var keys = Object.keys(localStorage), out = [], i, k, name = ""; for (i = 0; i &lt; keys.length; i++) { k = keys[i]; name = vault.friendlyName(k); if (name !== k &amp;&amp; localStorage[k]) { out.push({name: name, key: k}); } } out.sort(function (a, b) { return a.name &gt; b.name ? 1 : -1; }); return out; }; </code></pre> <p>it works. If I void it, though...</p> <pre><code>vault.getDecks = function () { // console.log(localStorage); void localStorage; var keys = Object.keys(localStorage), out = [], i, k, name = ""; for (i = 0; i &lt; keys.length; i++) { k = keys[i]; name = vault.friendlyName(k); if (name !== k &amp;&amp; localStorage[k]) { out.push({name: name, key: k}); } } out.sort(function (a, b) { return a.name &gt; b.name ? 1 : -1; }); return out; }; </code></pre> <p>It does not work. It also doesn't work if I remove the void keyword and just have localStorage on its own as a statement.</p> <p>I don't know why, but console.log(localstorage) does seem to fix this, and I can call the localStorage whenever I want.</p> <p>Really freaking weird.</p> <p><strong>EDIT:</strong> I found a slightly better solution. Calling the 'length' attribute of localStorage works as well.</p> <pre><code>vault.getDecks = function () { //Weird hack to make FF load localStorage correctly... localStorage.length; var keys = Object.keys(localStorage), out = [], i, k, name = ""; for (i = 0; i &lt; keys.length; i++) { k = keys[i]; name = vault.friendlyName(k); if (name !== k &amp;&amp; localStorage[k]) { out.push({name: name, key: k}); } } out.sort(function (a, b) { return a.name &gt; b.name ? 1 : -1; }); return out; }; </code></pre> <p>This is a bit better in that it doesn't log anything...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload