Skip to content

Commit

Permalink
always use recommended localStorage getter/setters
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrhode2 committed Dec 27, 2012
1 parent 5db8861 commit 38723dc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,21 @@ It works the same as accessing an Object in JavaScript, but persists the
value across sessions.

<pre>
localStorage.title = "Welcome!"
localStorage.title //=> "Welcome!"
localStorage.setItem("title", "Welcome!")
localStorage.getItem("title") //=> "Welcome!"

delete localStorage.title
localStorage.title //=> undefined
localStorage.removeItem("title")
localStorage.getItem("title") //=> null
</pre>

Browsers can offer different amounts of storage using this API. The
iPhone, for instance, offers 5MB of storage, after which it asks the
user for permission to store an additional 10MB.

You can reclaim storage from a key by <code>delete</code>ing it or
You can reclaim storage from a key by using the <code>removeItem</code> it or
by overwriting its value. You can also enumerate over all keys in
the localStorage using the normal JavaScript <code>for/in</code>
API.
loop.

In combination with the App Cache, you can use Local Storge to store
data on the device, making it possible to show stale data to your
Expand All @@ -170,7 +170,7 @@ jQuery(function($) {
// the HTML will be present regardless of online status
var updateArticles = function(object) {
template = $("#articles")
localStorage.articles = JSON.stringify(object);
localStorage.setItem("articles", JSON.stringify(object));
$("#article-list").html(template.render(object));
}

Expand Down Expand Up @@ -199,7 +199,7 @@ jQuery(function($) {
// update the HTML with the stale articles. Even if
// the user never gets online, they will at least
// see the stale content
if(localStorage.articles) updateArticles(JSON.parse(localStorage.articles));
if(localStorage.getItem("articles")) updateArticles(JSON.parse(localStorage.getItem("articles")));

// If the user was offline, and goes online, ask
// the server for updates
Expand All @@ -208,4 +208,4 @@ jQuery(function($) {
// If the user is online, ask for updates now
if(window.navigator.onLine) remoteUpdate();
})
</pre>
</pre>

1 comment on commit 38723dc

@SleeplessByte
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.