From 4345857bb0e2dd82561e7486e974c69ba5fb4976 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 6 Jan 2014 00:58:36 +0100 Subject: [PATCH] fix(scope): fix $properties not visible using [] -Fixed broken containsKey. -Refactored operator[]. --- lib/core/scope.dart | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/core/scope.dart b/lib/core/scope.dart index 928e79ff6..08b60ff37 100644 --- a/lib/core/scope.dart +++ b/lib/core/scope.dart @@ -62,10 +62,16 @@ class Scope implements Map { bool _skipAutoDigest = false; bool _disabled = false; + _set$Properties() { + _properties[r'this'] = this; + _properties[r'$id'] = this.$id; + _properties[r'$parent'] = this.$parent; + _properties[r'$root'] = this.$root; + } + Scope(this._exceptionHandler, this._parser, ScopeDigestTTL ttl, this._zone, this._perf): $parent = null, _isolate = false, _lazy = false, _ttl = ttl.ttl { - _properties[r'this']= this; $root = this; $id = '_${$root._nextId++}'; _innerAsyncQueue = []; @@ -74,12 +80,12 @@ class Scope implements Map { // Set up the zone to auto digest this scope. _zone.onTurnDone = _autoDigestOnTurnDone; _zone.onError = (e, s, ls) => _exceptionHandler(e, s); + _set$Properties(); } Scope._child(Scope parent, bool this._isolate, bool this._lazy, Profiler this._perf): $parent = parent, _ttl = parent._ttl, _parser = parent._parser, _exceptionHandler = parent._exceptionHandler, _zone = parent._zone { - _properties[r'this'] = this; $root = $parent.$root; $id = '_${$root._nextId++}'; _innerAsyncQueue = $parent._innerAsyncQueue; @@ -92,6 +98,7 @@ class Scope implements Map { } else { $parent._childHead = $parent._childTail = this; } + _set$Properties(); } _autoDigestOnTurnDone() { @@ -107,23 +114,27 @@ class Scope implements Map { (a is String && b is String && a == b) || (a is num && b is num && a.isNaN && b.isNaN); - containsKey(String name) => this[name] != null; + containsKey(String name) { + for (var scope = this; scope != null; scope = scope.$parent) { + if (scope._properties.containsKey(name)) { + return true; + } else if(scope._isolate) { + break; + } + } + return false; + } + remove(String name) => this._properties.remove(name); operator []=(String name, value) => _properties[name] = value; operator [](String name) { - if (name == r'$id') return this.$id; - if (name == r'$parent') return this.$parent; - if (name == r'$root') return this.$root; - var scope = this; - do { + for (var scope = this; scope != null; scope = scope.$parent) { if (scope._properties.containsKey(name)) { return scope._properties[name]; - } else if (!scope._isolate) { - scope = scope.$parent; - } else { - return null; + } else if(scope._isolate) { + break; } - } while(scope != null); + } return null; }