| 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 @CustomTag('polymer-localstorage') | |
| 11 class PolymerLocalStorage extends PolymerElement { | |
| 12 @published String name; | |
| 13 @published var value; | |
| 14 @published bool useRaw = false; | |
| 15 | |
| 16 factory PolymerLocalStorage() => new Element.tag('polymer-localstorage'); | |
| 17 PolymerLocalStorage.created() : super.created(); | |
| 18 | |
| 19 void ready() { | |
| 20 load(); | |
| 21 } | |
| 22 | |
| 23 void valueChanged() { | |
| 24 save(); | |
| 25 } | |
| 26 | |
| 27 void load() { | |
| 28 var s = window.localStorage[name]; | |
| 29 if (s != null && !useRaw) { | |
| 30 value = JSON.decode(s); | |
| 31 } else { | |
| 32 value = s; | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 void save() { | |
| 37 window.localStorage[name] = useRaw ? value : JSON.encode(value); | |
| 38 } | |
| 39 } | |
| OLD | NEW |