| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library searchable_list.searchable_list; | 5 library searchable_list.searchable_list; |
| 6 | 6 |
| 7 import 'package:polymer/polymer.dart'; | 7 import 'package:polymer/polymer.dart'; |
| 8 | 8 |
| 9 @CustomTag('searchable-list') | 9 @CustomTag('searchable-list') |
| 10 class SearchableList extends PolymerElement { | 10 class SearchableList extends PolymerElement { |
| 11 @observable bool applyAuthorStyles = true; | 11 @observable bool applyAuthorStyles = true; |
| 12 @observable String searchParam; | 12 @observable String searchParam; |
| 13 @published List<String> data = []; | 13 @published List<String> data = []; |
| 14 final List<String> results = toObservable([]); | 14 final List<String> results = toObservable([]); |
| 15 | 15 |
| 16 SearchableList.created() : super.created(); | 16 SearchableList.created() : super.created(); |
| 17 | 17 |
| 18 attached() { | 18 attached() { |
| 19 super.attached(); | 19 super.attached(); |
| 20 results.addAll(data); | 20 results.addAll(data); |
| 21 onPropertyChange(this, #searchParam, search); | 21 onPropertyChange(this, #searchParam, search); |
| 22 } | 22 } |
| 23 | 23 |
| 24 search() { | 24 search() { |
| 25 results.clear(); | 25 results.clear(); |
| 26 String lower = searchParam.toLowerCase(); | 26 String lower = searchParam.toLowerCase(); |
| 27 results.addAll(data.where((d) => d.toLowerCase().contains(lower))); | 27 results.addAll(data.where((d) => d.toLowerCase().contains(lower))); |
| 28 } | 28 } |
| 29 } | 29 } |
| OLD | NEW |