Skip to content

Commit 70c976a

Browse files
committed
docs(examples): add simple example
1 parent 6f4a68d commit 70c976a

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

examples/index.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf8" />
5+
<title>Simple localForage-sessionStorageWrapper example</title>
6+
</head>
7+
<body>
8+
<script src="../bower_components/localforage/dist/localforage.js"></script>
9+
<script src="../src/localforage-sessionstoragewrapper.js"></script>
10+
<script>
11+
var sessionStorageWrapper = window.sessionStorageWrapper;
12+
13+
localforage.defineDriver(sessionStorageWrapper).then(function() {
14+
// Forcing sessionStorage here. Feel free to switch to other drivers :)
15+
localforage.setDriver(sessionStorageWrapper._driver).then(function() {
16+
var key = 'STORE_KEY';
17+
var value = 'What we save offline';
18+
var UNKNOWN_KEY = 'unknown_key';
19+
20+
localforage.getItem(key).then(function(readValue) {
21+
if (readValue) {
22+
console.log(key + ' was already in ' + localforage.driver() + ', with value: ' + readValue);
23+
} else {
24+
console.log(localforage.driver() + ' did not contain ' + key);
25+
}
26+
27+
localforage.setItem(key, value, function() {
28+
console.log('Saved: ' + value);
29+
30+
localforage.getItem(key, function(err, readValue) {
31+
console.log('Read: ', readValue);
32+
});
33+
34+
// Since this key hasn't been set yet, we'll get a null value
35+
localforage.getItem(UNKNOWN_KEY, function(err, readValue) {
36+
console.log('Result of reading ' + UNKNOWN_KEY, readValue);
37+
});
38+
});
39+
});
40+
});
41+
});
42+
</script>
43+
44+
<p>
45+
Check your console log.
46+
</p>
47+
<p>
48+
Restart your browser or open a new incognito tab, <br />
49+
to verify that everything is stored just for a session.
50+
</p>
51+
</body>
52+
</html>

0 commit comments

Comments
 (0)