From 3410f65e790a81d457b4f4601a1e760a6f8ede5e Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski Date: Wed, 16 Oct 2013 15:15:21 +0200 Subject: perf(jqLite): implement and use the `empty` method in place of `html(‘’)` jQuery's elem.html('') is way slower than elem.empty(). As clearing element contents happens quite often in certain scenarios, switching to using .empty() provides a significant performance boost when using Angular with jQuery. Closes #4457 --- test/jqLiteSpec.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'test/jqLiteSpec.js') diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 09be1c1c..c4f47dcd 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -322,7 +322,7 @@ describe('jqLite', function() { }); - it('should emit $destroy event if an element is removed via html()', inject(function(log) { + it('should emit $destroy event if an element is removed via html(\'\')', inject(function(log) { var element = jqLite('
x
'); element.find('span').on('$destroy', log.fn('destroyed')); @@ -333,6 +333,17 @@ describe('jqLite', function() { })); + it('should emit $destroy event if an element is removed via empty()', inject(function(log) { + var element = jqLite('
x
'); + element.find('span').on('$destroy', log.fn('destroyed')); + + element.empty(); + + expect(element.html()).toBe(''); + expect(log).toEqual('destroyed'); + })); + + it('should retrieve all data if called without params', function() { var element = jqLite(a); expect(element.data()).toEqual({}); @@ -786,7 +797,7 @@ describe('jqLite', function() { }); - it('should read/write value', function() { + it('should read/write a value', function() { var element = jqLite('
abc
'); expect(element.length).toEqual(1); expect(element[0].innerHTML).toEqual('abc'); @@ -797,6 +808,16 @@ describe('jqLite', function() { }); + describe('empty', function() { + it('should write a value', function() { + var element = jqLite('
abc
'); + expect(element.length).toEqual(1); + expect(element.empty() == element).toBeTruthy(); + expect(element.html()).toEqual(''); + }); + }); + + describe('on', function() { it('should bind to window on hashchange', function() { if (jqLite.fn) return; // don't run in jQuery -- cgit v1.2.3