OLD | NEW |
1 // Copyright 2013 The Polymer Authors. All rights reserved. | 1 // Copyright 2013 The Polymer Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 library todomvc.web.lib_elements.polymer_localstorage; | 4 library todomvc.web.lib_elements.polymer_localstorage; |
5 | 5 |
6 import 'dart:convert' show JSON; | 6 import 'dart:convert' show JSON; |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'package:polymer/polymer.dart'; | 8 import 'package:polymer/polymer.dart'; |
9 | 9 |
| 10 // TODO(jmesserly): replace with interop to <polymer-localstorage>. |
10 @CustomTag('polymer-localstorage') | 11 @CustomTag('polymer-localstorage') |
11 class PolymerLocalStorage extends PolymerElement { | 12 class PolymerLocalStorage extends PolymerElement { |
12 @published String name; | 13 @published String name; |
13 @published var value; | 14 @published var value; |
14 @published bool useRaw = false; | 15 @published bool useRaw = false; |
15 | 16 |
16 factory PolymerLocalStorage() => new Element.tag('polymer-localstorage'); | 17 factory PolymerLocalStorage() => new Element.tag('polymer-localstorage'); |
17 PolymerLocalStorage.created() : super.created(); | 18 PolymerLocalStorage.created() : super.created(); |
18 | 19 |
19 void ready() { | 20 void ready() { |
(...skipping 10 matching lines...) Expand all Loading... |
30 value = JSON.decode(s); | 31 value = JSON.decode(s); |
31 } else { | 32 } else { |
32 value = s; | 33 value = s; |
33 } | 34 } |
34 } | 35 } |
35 | 36 |
36 void save() { | 37 void save() { |
37 window.localStorage[name] = useRaw ? value : JSON.encode(value); | 38 window.localStorage[name] = useRaw ? value : JSON.encode(value); |
38 } | 39 } |
39 } | 40 } |
OLD | NEW |