OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// @domName Storage | 5 /// @domName Storage |
| 6 /** |
| 7 * The type used by the |
| 8 * [Window.localStorage] and [Window.sessionStorage] properties. |
| 9 * Storage is implemented as a Map<String, String>. |
| 10 * |
| 11 * To store and get values, use Dart's built-in map syntax: |
| 12 * |
| 13 * window.localStorage['key1'] = 'val1'; |
| 14 * window.localStorage['key2'] = 'val2'; |
| 15 * window.localStorage['key3'] = 'val3'; |
| 16 * assert(window.localStorage['key3'] == 'val3'); |
| 17 * |
| 18 * You can use [Map](http://api.dartlang.org/dart_core/Map.html) APIs |
| 19 * such as containsValue(), clear(), and length: |
| 20 * |
| 21 * assert(window.localStorage.containsValue('does not exist') == false); |
| 22 * window.localStorage.clear(); |
| 23 * assert(window.localStorage.length == 0); |
| 24 * |
| 25 * For more examples of using this API, see |
| 26 * [localstorage_test.dart](http://code.google.com/p/dart/source/browse/branches
/bleeding_edge/dart/tests/html/localstorage_test.dart). |
| 27 * For details on using the Map API, see the |
| 28 * [Maps](http://www.dartlang.org/docs/library-tour/#maps-aka-dictionaries-or-ha
shes) |
| 29 * section of the library tour. |
| 30 * |
| 31 */ |
6 interface Storage extends Map<String, String> { | 32 interface Storage extends Map<String, String> { |
7 | 33 |
8 /** @domName Storage.length */ | 34 /** @domName Storage.length */ |
9 final int $dom_length; | 35 final int $dom_length; |
10 | 36 |
11 /** @domName Storage.clear */ | 37 /** @domName Storage.clear */ |
12 void $dom_clear(); | 38 void $dom_clear(); |
13 | 39 |
14 /** @domName Storage.getItem */ | 40 /** @domName Storage.getItem */ |
15 String $dom_getItem(String key); | 41 String $dom_getItem(String key); |
16 | 42 |
17 /** @domName Storage.key */ | 43 /** @domName Storage.key */ |
18 String $dom_key(int index); | 44 String $dom_key(int index); |
19 | 45 |
20 /** @domName Storage.removeItem */ | 46 /** @domName Storage.removeItem */ |
21 void $dom_removeItem(String key); | 47 void $dom_removeItem(String key); |
22 | 48 |
23 /** @domName Storage.setItem */ | 49 /** @domName Storage.setItem */ |
24 void $dom_setItem(String key, String data); | 50 void $dom_setItem(String key, String data); |
25 | 51 |
26 } | 52 } |
OLD | NEW |