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 polymer_expressions.eval; | 5 library polymer_expressions.eval; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty], | 10 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty], |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 : super(value); | 413 : super(value); |
414 | 414 |
415 accept(Visitor v) => v.visitMapLiteralEntry(this); | 415 accept(Visitor v) => v.visitMapLiteralEntry(this); |
416 } | 416 } |
417 | 417 |
418 class IdentifierObserver extends ExpressionObserver<Identifier> | 418 class IdentifierObserver extends ExpressionObserver<Identifier> |
419 implements Identifier { | 419 implements Identifier { |
420 | 420 |
421 IdentifierObserver(Identifier value) : super(value); | 421 IdentifierObserver(Identifier value) : super(value); |
422 | 422 |
423 dynamic get value => _expr.value; | 423 String get value => (_expr as Identifier).value; |
424 | 424 |
425 _updateSelf(Scope scope) { | 425 _updateSelf(Scope scope) { |
426 _value = scope[_expr.value]; | 426 _value = scope[value]; |
427 | 427 |
428 var owner = scope.ownerOf(_expr.value); | 428 var owner = scope.ownerOf(value); |
429 if (owner is Observable) { | 429 if (owner is Observable) { |
430 _subscription = (owner as Observable).changes.listen( | 430 var symbol = new Symbol(value); |
431 (List<ChangeRecord> changes) { | 431 _subscription = (owner as Observable).changes.listen((changes) { |
432 var symbol = new Symbol(_expr.value); | 432 if (changes.any( |
433 if (changes.any((c) => c.changes(symbol))) { | 433 (c) => c is PropertyChangeRecord && c.name == symbol)) { |
434 _invalidate(scope); | 434 _invalidate(scope); |
435 } | 435 } |
436 }); | 436 }); |
437 } | 437 } |
438 } | 438 } |
439 | 439 |
440 accept(Visitor v) => v.visitIdentifier(this); | 440 accept(Visitor v) => v.visitIdentifier(this); |
441 } | 441 } |
442 | 442 |
443 class ParenthesizedObserver extends ExpressionObserver<ParenthesizedExpression> | 443 class ParenthesizedObserver extends ExpressionObserver<ParenthesizedExpression> |
444 implements ParenthesizedExpression { | 444 implements ParenthesizedExpression { |
445 final ExpressionObserver child; | 445 final ExpressionObserver child; |
446 | 446 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 // special case [] because we don't need mirrors | 538 // special case [] because we don't need mirrors |
539 if (_expr.method == '[]') { | 539 if (_expr.method == '[]') { |
540 assert(args.length == 1); | 540 assert(args.length == 1); |
541 var key = args[0]; | 541 var key = args[0]; |
542 _value = receiverValue[key]; | 542 _value = receiverValue[key]; |
543 | 543 |
544 if (receiverValue is Observable) { | 544 if (receiverValue is Observable) { |
545 _subscription = (receiverValue as Observable).changes.listen( | 545 _subscription = (receiverValue as Observable).changes.listen( |
546 (List<ChangeRecord> changes) { | 546 (List<ChangeRecord> changes) { |
547 if (changes.any((c) => | 547 if (changes.any((c) => |
548 c is MapChangeRecord && c.changes(key))) { | 548 c is MapChangeRecord && c.key == key)) { |
549 _invalidate(scope); | 549 _invalidate(scope); |
550 } | 550 } |
551 }); | 551 }); |
552 } | 552 } |
553 } else { | 553 } else { |
554 var mirror = reflect(receiverValue); | 554 var mirror = reflect(receiverValue); |
555 var symbol = new Symbol(_expr.method); | 555 var symbol = new Symbol(_expr.method); |
556 _value = (_expr.isGetter) | 556 _value = (_expr.isGetter) |
557 ? mirror.getField(symbol).reflectee | 557 ? mirror.getField(symbol).reflectee |
558 : mirror.invoke(symbol, args, null).reflectee; | 558 : mirror.invoke(symbol, args, null).reflectee; |
559 | 559 |
560 if (receiverValue is Observable) { | 560 if (receiverValue is Observable) { |
561 _subscription = (receiverValue as Observable).changes.listen( | 561 _subscription = (receiverValue as Observable).changes.listen( |
562 (List<ChangeRecord> changes) { | 562 (List<ChangeRecord> changes) { |
563 if (changes.any((c) => c.changes(symbol))) { | 563 if (changes.any( |
| 564 (c) => c is PropertyChangeRecord && c.name == symbol)) { |
564 _invalidate(scope); | 565 _invalidate(scope); |
565 } | 566 } |
566 }); | 567 }); |
567 } | 568 } |
568 } | 569 } |
569 } | 570 } |
570 } | 571 } |
571 | 572 |
572 accept(Visitor v) => v.visitInvoke(this); | 573 accept(Visitor v) => v.visitInvoke(this); |
573 } | 574 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 * This does not work for calls that need to pass more than one argument. | 645 * This does not work for calls that need to pass more than one argument. |
645 */ | 646 */ |
646 call(arg0) => mirror.invoke(symbol, [arg0], null).reflectee; | 647 call(arg0) => mirror.invoke(symbol, [arg0], null).reflectee; |
647 } | 648 } |
648 | 649 |
649 class EvalException implements Exception { | 650 class EvalException implements Exception { |
650 final String message; | 651 final String message; |
651 EvalException(this.message); | 652 EvalException(this.message); |
652 String toString() => "EvalException: $message"; | 653 String toString() => "EvalException: $message"; |
653 } | 654 } |
OLD | NEW |