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