| 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 fancy_syntax; | 5 library fancy_syntax; |
| 6 | 6 |
| 7 import 'dart:async'; |
| 7 import 'dart:html'; | 8 import 'dart:html'; |
| 8 import 'dart:collection'; | 9 import 'dart:collection'; |
| 9 import 'package:mdv_observe/mdv_observe.dart'; | 10 import 'package:mdv_observe/mdv_observe.dart'; |
| 10 | 11 |
| 12 import 'async.dart'; |
| 11 import 'eval.dart'; | 13 import 'eval.dart'; |
| 12 import 'expression.dart'; | 14 import 'expression.dart'; |
| 13 import 'parser.dart'; | 15 import 'parser.dart'; |
| 14 import 'visitor.dart'; | 16 import 'visitor.dart'; |
| 15 | 17 |
| 16 class FancySyntax extends CustomBindingSyntax { | 18 class FancySyntax extends CustomBindingSyntax { |
| 17 | 19 |
| 18 final Map<String, Object> globals; | 20 final Map<String, Object> globals; |
| 19 | 21 |
| 20 FancySyntax({Map<String, Object> globals}) | 22 FancySyntax({Map<String, Object> globals}) |
| 21 : globals = (globals == null) ? new Map<String, Object>() : globals; | 23 : globals = (globals == null) ? new Map<String, Object>() : globals; |
| 22 | 24 |
| 23 _Binding getBinding(model, String path, name, node) { | 25 _Binding getBinding(model, String path, name, node) { |
| 24 if (path != null) { | 26 if (path != null) { |
| 25 if (path.isEmpty) { | 27 var expr = new Parser(path).parse(); |
| 26 // avoid creating an unneccesary scope for the top-level template | 28 if (model is! Scope) { |
| 27 return null; | |
| 28 } else if (model is! Scope) { | |
| 29 model = new Scope(model: model, variables: globals); | 29 model = new Scope(model: model, variables: globals); |
| 30 } | 30 } |
| 31 var expr = new Parser(path).parse(); | |
| 32 return new _Binding(expr, model); | 31 return new _Binding(expr, model); |
| 33 } else { | 32 } else { |
| 34 return null; | 33 return null; |
| 35 } | 34 } |
| 36 } | 35 } |
| 37 | 36 |
| 38 getInstanceModel(Element template, model) { | 37 getInstanceModel(Element template, model) { |
| 39 if (model is! Scope) { | 38 if (model is! Scope) { |
| 40 var _scope = new Scope(model: model, variables: globals); | 39 var _scope = new Scope(model: model, variables: globals); |
| 41 return _scope; | 40 return _scope; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 86 |
| 88 getValueWorkaround(key) { | 87 getValueWorkaround(key) { |
| 89 if (key == _VALUE) return value; | 88 if (key == _VALUE) return value; |
| 90 } | 89 } |
| 91 | 90 |
| 92 setValueWorkaround(key, v) { | 91 setValueWorkaround(key, v) { |
| 93 if (key == _VALUE) value = v; | 92 if (key == _VALUE) value = v; |
| 94 } | 93 } |
| 95 | 94 |
| 96 } | 95 } |
| OLD | NEW |