Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: samples/third_party/todomvc/web/lib-elements/polymer_localstorage.dart

Issue 60353013: Update TodoMVC based on https://github.com/polymer/todomvc (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix pubspecs Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 @observable bool useRaw = false;
13 @observable String name;
14 @observable var value;
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698