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

Unified Diff: samples/third_party/todomvc/web/lib-elements/polymer_selection.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: merged 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 side-by-side diff with in-line comments
Download patch
Index: samples/third_party/todomvc/web/lib-elements/polymer_selection.dart
diff --git a/samples/third_party/todomvc/web/lib-elements/polymer_selection.dart b/samples/third_party/todomvc/web/lib-elements/polymer_selection.dart
new file mode 100644
index 0000000000000000000000000000000000000000..315c425b1a20cb112c0483980a2c5bd48189f518
--- /dev/null
+++ b/samples/third_party/todomvc/web/lib-elements/polymer_selection.dart
@@ -0,0 +1,66 @@
+// Copyright 2013 The Polymer Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+library todomvc.web.lib_elements.polymer_selection;
+
+import 'dart:html';
+import 'package:polymer/polymer.dart';
+
+@CustomTag('polymer-selection')
+class PolymerSelection extends PolymerElement {
+ @published bool multi = false;
+ @observable final selection = new ObservableList();
+
+ factory PolymerSelection() => new Element.tag('polymer-selection');
+ PolymerSelection.created() : super.created();
+
+ void ready() {
+ clear();
+ }
+
+ void clear() {
+ selection.clear();
+ }
+
+ getSelection() {
+ if (multi) return selection;
+ if (selection.isNotEmpty) return selection[0];
+ return null;
+ }
+
+ bool isSelected(item) => selection.contains(item);
+
+ void setItemSelected(item, bool isSelected) {
+ if (item != null) {
+ if (isSelected) {
+ selection.add(item);
+ } else {
+ selection.remove(item);
+ }
+ // TODO(sjmiles): consider replacing with summary
+ // notifications (asynchronous job)
+ asyncFire("polymer-select", detail:
+ new PolymerSelectEventDetail(isSelected, item));
+ }
+ }
+
+ select(item) {
+ if (multi) {
+ toggle(item);
+ } else if (getSelection() != item) {
+ setItemSelected(getSelection(), false);
+ setItemSelected(item, true);
+ }
+ }
+
+ toggle(item) {
+ setItemSelected(item, !isSelected(item));
+ }
+}
+
+class PolymerSelectEventDetail {
+ final bool isSelected;
+ final item;
+
+ PolymerSelectEventDetail(this.isSelected, this.item);
+}

Powered by Google App Engine
This is Rietveld 408576698