Skip to content
This repository was archived by the owner on Jun 3, 2020. It is now read-only.

Commit 1171e99

Browse files
author
Seth Ladd
committed
move COPYING to LICENSE, and add local storage example
1 parent 6426a06 commit 1171e99

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Dart Editor
22
.children
33
.project
4+
*.dart.js
5+
*.dart.js.map

COPYING renamed to LICENSE

File renamed without changes.

localstorage/basics/README

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Local Storage is a simple key/value storage interface
2+
for Strings. Use Dart's local storage interface as a
3+
Map.
4+
5+
See also http://api.dartlang.org/docs/continuous/dart_html/Storage.html
6+
and https://developer.mozilla.org/en-US/docs/DOM/Storage
7+
8+
Note, local storage, though widely supported, is a
9+
synchronous API. Because it involves IO, this interface
10+
should not be used for high throughput operations.
11+
You might consider IndexedDB as an alternative.
12+
13+
For simple string keys and values, and as a replacement
14+
for cookies, local storage is useful.

localstorage/basics/localstorage.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
#import('dart:html');
6+
7+
void main() {
8+
InputElement username = query('#username');
9+
InputElement submit = query('#save');
10+
Element output = query('#username-output');
11+
Storage localStorage = window.localStorage;
12+
13+
// local storage is a Map, supporting string keys and values
14+
String savedUsername = localStorage['username'];
15+
16+
if (savedUsername != null) {
17+
output.text = savedUsername;
18+
}
19+
20+
submit.on.click.add((Event e) {
21+
output.text = username.value;
22+
localStorage['username'] = username.value;
23+
});
24+
}

localstorage/basics/localstorage.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
3+
<!--
4+
Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
5+
for details. All rights reserved. Use of this source code is governed by a
6+
BSD-style license that can be found in the LICENSE file.
7+
-->
8+
9+
<html>
10+
<head>
11+
<meta charset="utf-8">
12+
<title>Local Storage in Dart</title>
13+
</head>
14+
<body>
15+
<h1>Local Storage in Dart</h1>
16+
17+
<p>
18+
From local storage: <output id="username-output"></output>
19+
</p>
20+
21+
<label for="username">Username:</label>
22+
<input type="text" name="username" id="username">
23+
<input type="submit" id="save" value="Save">
24+
25+
<script type="application/dart" src="localstorage.dart"></script>
26+
<script src="http://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script>
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)