From eb6ba0d76dcb62c95f67bda08a643aa76ea6af8b Mon Sep 17 00:00:00 2001 From: Pavel Jbanov Date: Thu, 14 Nov 2013 16:42:30 -0800 Subject: [PATCH] fix(compiler): don't create watchers for attr mappings if no attr is specified Closes #265 --- lib/core_dom/compiler.dart | 3 +++ test/core_dom/compiler_spec.dart | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/core_dom/compiler.dart b/lib/core_dom/compiler.dart index f7f041163..c61c654f4 100644 --- a/lib/core_dom/compiler.dart +++ b/lib/core_dom/compiler.dart @@ -151,6 +151,7 @@ class Compiler { break; case '<=>': mappingFn = (NodeAttrs attrs, Scope scope, Object dst) { + if (attrs[attrName] == null) return; Expression attrExprFn = _parser(attrs[attrName]); var shadowValue = null; scope.$watch( @@ -172,6 +173,7 @@ class Compiler { break; case '=>': mappingFn = (NodeAttrs attrs, Scope scope, Object dst) { + if (attrs[attrName] == null) return; Expression attrExprFn = _parser(attrs[attrName]); var shadowValue = null; scope.$watch( @@ -182,6 +184,7 @@ class Compiler { break; case '=>!': mappingFn = (NodeAttrs attrs, Scope scope, Object dst) { + if (attrs[attrName] == null) return; Expression attrExprFn = _parser(attrs[attrName]); var stopWatching; stopWatching = scope.$watch( diff --git a/test/core_dom/compiler_spec.dart b/test/core_dom/compiler_spec.dart index 2845b042e..23d746488 100644 --- a/test/core_dom/compiler_spec.dart +++ b/test/core_dom/compiler_spec.dart @@ -244,6 +244,14 @@ main() => describe('dte.compiler', () { expect($rootScope.done).toEqual(true); }))); + it('should should not create any watchers if no attributes are specified', async(inject((Profiler perf) { + var element = $(r'
'); + $compile(element)(injector, element); + microLeap(); + injector.get(Scope).$digest(); + expect(perf.counters['ng.scope.watchers']).toEqual(0); + }))); + it('should create a component with I/O and "=" binding value should be available', async(inject(() { $rootScope.name = 'misko'; var element = $(r'
');