Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library eval_box_element; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:html'; | |
| 9 import 'observatory_element.dart'; | |
| 10 import 'package:polymer/polymer.dart'; | |
| 11 | |
| 12 | |
| 13 typedef Future<ObservableMap> evalType(String text); | |
| 14 | |
| 15 | |
| 16 @CustomTag('eval-box') | |
| 17 class EvalBoxElement extends ObservatoryElement { | |
| 18 @observable String text; | |
| 19 @observable String lineMode = "1-line"; | |
| 20 | |
| 21 @published evalType callback; | |
| 22 @published ObservableList expressions = toObservable([]); | |
|
Cutch
2014/03/11 22:06:46
Should this be marked as @observable instead of @p
turnidge
2014/03/11 22:23:22
Done.
| |
| 23 @published ObservableList results = toObservable([]); | |
| 24 | |
| 25 void updateLineMode(Event e, var detail, Node target) { | |
| 26 lineMode = (e.target as InputElement).value; | |
| 27 if (lineMode == '1-line') { | |
| 28 text = text.replaceAll('\n', ' '); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 void eval(Event e, var detail, Node target) { | |
| 33 // Prevent any form action. | |
| 34 e.preventDefault(); | |
| 35 | |
| 36 // Clear the text box. | |
| 37 var expr = text; | |
| 38 text = ''; | |
| 39 | |
| 40 // Use provided callback to eval the expression. | |
| 41 if (callback != null) { | |
| 42 var map = toObservable({}); | |
| 43 map['expr'] = expr; | |
| 44 results.insert(0, map); | |
| 45 callback(expr).then((result) { | |
| 46 map['value'] = result; | |
| 47 }); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 void selectExpr(MouseEvent e) { | |
| 52 text = e.target.getAttribute('expr'); | |
| 53 } | |
| 54 | |
| 55 EvalBoxElement.created() : super.created(); | |
| 56 } | |
| OLD | NEW |