11/*!
2- * ui-grid - v4.0.1 - 2016-12-15
2+ * ui-grid - v4.0.1-138d149 - 2016-12-29
33 * Copyright (c) 2016 ; License: MIT
44 */
55
@@ -2273,13 +2273,11 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
22732273 angular.element($window).on('resize', applyHideMenu);
22742274 }
22752275
2276- $scope.$on('$destroy', function () {
2277- angular.element(document).off('click touchstart', applyHideMenu);
2278- });
2279-
2280-
2281- $scope.$on('$destroy', function() {
2276+ $scope.$on('$destroy', function unbindEvents() {
22822277 angular.element($window).off('resize', applyHideMenu);
2278+ angular.element(document).off('click touchstart', applyHideMenu);
2279+ $elm.off('keyup', checkKeyUp);
2280+ $elm.off('keydown', checkKeyDown);
22832281 });
22842282
22852283 if (uiGridCtrl) {
@@ -3214,7 +3212,9 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
32143212 }
32153213 }
32163214
3217-
3215+ $scope.$on('$destroy', function unbindEvents() {
3216+ $elm.off();
3217+ });
32183218 },
32193219 controller: ['$scope', function ($scope) {
32203220 this.rowStyle = function (index) {
@@ -4784,7 +4784,7 @@ angular.module('ui.grid')
47844784 * @methodOf ui.grid.class:Grid
47854785 * @description returns the GridRow that contains the rowEntity
47864786 * @param {object} rowEntity the gridOptions.data array element instance
4787- * @param {array} rows [optional] the rows to look in - if not provided then
4787+ * @param {array} lookInRows [optional] the rows to look in - if not provided then
47884788 * looks in grid.rows
47894789 */
47904790 Grid.prototype.getRow = function getRow(rowEntity, lookInRows) {
@@ -4849,13 +4849,20 @@ angular.module('ui.grid')
48494849 self.rows.length = 0;
48504850
48514851 newRawData.forEach( function( newEntity, i ) {
4852- var newRow;
4852+ var newRow, oldRow;
4853+
48534854 if ( self.options.enableRowHashing ){
48544855 // if hashing is enabled, then this row will be in the hash if we already know about it
4855- newRow = oldRowHash.get( newEntity );
4856+ oldRow = oldRowHash.get( newEntity );
48564857 } else {
48574858 // otherwise, manually search the oldRows to see if we can find this row
4858- newRow = self.getRow(newEntity, oldRows);
4859+ oldRow = self.getRow(newEntity, oldRows);
4860+ }
4861+
4862+ // update newRow to have an entity
4863+ if ( oldRow ) {
4864+ newRow = oldRow;
4865+ newRow.entity = newEntity;
48594866 }
48604867
48614868 // if we didn't find the row, it must be new, so create it
@@ -11786,6 +11793,11 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
1178611793 for ( var i = mouseWheeltoBind.length; i; ) {
1178711794 $elm.on(mouseWheeltoBind[--i], cbs[fn]);
1178811795 }
11796+ $elm.on('$destroy', function unbindEvents() {
11797+ for ( var i = mouseWheeltoBind.length; i; ) {
11798+ $elm.off(mouseWheeltoBind[--i], cbs[fn]);
11799+ }
11800+ });
1178911801 };
1179011802 s.off.mousewheel = function (elm, fn) {
1179111803 var $elm = angular.element(elm);
@@ -16436,7 +16448,11 @@ module.filter('px', function() {
1643616448 });
1643716449
1643816450
16439- $scope.$on( '$destroy', rowWatchDereg );
16451+ $scope.$on('$destroy', function destroyEvents() {
16452+ rowWatchDereg();
16453+ // unbind all jquery events in order to avoid memory leaks
16454+ $elm.off();
16455+ });
1644016456
1644116457 function registerBeginEditEvents() {
1644216458 $elm.on('dblclick', beginEdit);
@@ -16971,6 +16987,11 @@ module.filter('px', function() {
1697116987
1697216988 return true;
1697316989 });
16990+
16991+ $scope.$on('$destroy', function unbindEvents() {
16992+ // unbind all jquery events in order to avoid memory leaks
16993+ $elm.off();
16994+ });
1697416995 }
1697516996 };
1697616997 }
@@ -17114,6 +17135,11 @@ module.filter('px', function() {
1711417135 }
1711517136 return true;
1711617137 });
17138+
17139+ $scope.$on('$destroy', function unbindEvents() {
17140+ // unbind jquery events to prevent memory leaks
17141+ $elm.off();
17142+ });
1711717143 }
1711817144 };
1711917145 }
@@ -17206,7 +17232,7 @@ module.filter('px', function() {
1720617232 }
1720717233 };
1720817234
17209- $elm[0].addEventListener('change', handleFileSelect, false); // TODO: why the false on the end? Google
17235+ $elm[0].addEventListener('change', handleFileSelect, false);
1721017236
1721117237 $scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
1721217238 $elm[0].focus();
@@ -17216,13 +17242,17 @@ module.filter('px', function() {
1721617242 $scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
1721717243 });
1721817244 });
17245+
17246+ $scope.$on('$destroy', function unbindEvents() {
17247+ // unbind jquery events to prevent memory leaks
17248+ $elm.off();
17249+ $elm[0].removeEventListener('change', handleFileSelect, false);
17250+ });
1721917251 }
1722017252 };
1722117253 }
1722217254 };
1722317255 }]);
17224-
17225-
1722617256})();
1722717257
1722817258(function () {
@@ -22385,6 +22415,8 @@ module.filter('px', function() {
2238522415 movingElm.css({'width': reducedWidth + 'px'});
2238622416 }
2238722417 };
22418+
22419+ $scope.$on('$destroy', offAllEvents);
2238822420 }
2238922421 }
2239022422 };
@@ -25966,6 +25998,10 @@ module.filter('px', function() {
2596625998 window.setTimeout(function () { evt.target.onselectstart = null; }, 0);
2596725999 }
2596826000 }
26001+
26002+ $scope.$on('$destroy', function unbindEvents() {
26003+ $elm.off();
26004+ });
2596926005 }
2597026006 };
2597126007 }]);
0 commit comments