Skip to content

Commit

Permalink
perf(ui-grid.core): Remove unnecessary code.
Browse files Browse the repository at this point in the history
Refactoring and removing unnecessary code to improve performance.
  • Loading branch information
Portugal, Marcelo authored and mportuga committed Jul 9, 2018
1 parent fcfae6f commit cfec75c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 44 deletions.
28 changes: 8 additions & 20 deletions src/js/core/directives/ui-grid-render-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
compile: function() {
return {
pre: function prelink($scope, $elm, $attrs, controllers) {
var rowContainer, colContainer, gridContainerPrefix,
var rowContainer, colContainer,
uiGridCtrl = controllers[0],
containerCtrl = controllers[1],
grid = $scope.grid = uiGridCtrl.grid,
gridContainerId = 'grid-container';
grid = $scope.grid = uiGridCtrl.grid;

// Verify that the render container for this element exists
if (!$scope.rowContainerName) {
Expand All @@ -46,13 +45,10 @@

rowContainer = $scope.rowContainer = grid.renderContainers[$scope.rowContainerName];
colContainer = $scope.colContainer = grid.renderContainers[$scope.colContainerName];
gridContainerPrefix = $scope.containerId !== 'body' ? $scope.containerId + '-' : '';

containerCtrl.gridContainerId = gridContainerPrefix + gridContainerId;
containerCtrl.containerId = $scope.containerId;
containerCtrl.rowContainer = rowContainer;
containerCtrl.colContainer = colContainer;
containerCtrl.grid = grid;
},
post: function postlink($scope, $elm, $attrs, controllers) {
var uiGridCtrl = controllers[0],
Expand All @@ -70,6 +66,7 @@
// Scroll the render container viewport when the mousewheel is used
gridUtil.on.mousewheel($elm, function(event) {
var scrollEvent = new ScrollEvent(grid, rowContainer, colContainer, ScrollEvent.Sources.RenderContainerMouseWheel);

if (event.deltaY !== 0) {
var scrollYAmount = event.deltaY * -1 * event.deltaFactor;

Expand Down Expand Up @@ -107,23 +104,19 @@
}

// Let the parent container scroll if the grid is already at the top/bottom
if ((event.deltaY !== 0 && (scrollEvent.atTop(scrollTop) || scrollEvent.atBottom(scrollTop))) ||
(event.deltaX !== 0 && (scrollEvent.atLeft(scrollLeft) || scrollEvent.atRight(scrollLeft)))) {
// parent controller scrolls
}
else {
if (!((event.deltaY !== 0 && (scrollEvent.atTop(scrollTop) || scrollEvent.atBottom(scrollTop))) ||
(event.deltaX !== 0 && (scrollEvent.atLeft(scrollLeft) || scrollEvent.atRight(scrollLeft))))) {
event.preventDefault();
event.stopPropagation();
scrollEvent.fireThrottledScrollingEvent('', scrollEvent);
}

});

$elm.bind('$destroy', function() {
var eventsToUnbind = ['touchstart', 'touchmove', 'touchend', 'keydown', 'wheel', 'mousewheel',
'DomMouseScroll', 'MozMousePixelScroll'];
$elm.unbind('keydown');

eventsToUnbind.forEach(function(eventName) {
['touchstart', 'touchmove', 'touchend', 'keydown', 'wheel', 'mousewheel',
'DomMouseScroll', 'MozMousePixelScroll'].forEach(function(eventName) {
$elm.unbind(eventName);
});
});
Expand All @@ -137,11 +130,6 @@

var canvasHeight = rowContainer.getCanvasHeight();

// add additional height for scrollbar on left and right container
// if ($scope.containerId !== 'body') {
// canvasHeight -= grid.scrollbarHeight;
// }

var viewportHeight = rowContainer.getViewportHeight();
// shorten the height to make room for a scrollbar placeholder
if (colContainer.needsHScrollbarPlaceholder()) {
Expand Down
27 changes: 8 additions & 19 deletions src/js/i18n/ui-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
*
* @description Services for i18n
*/
module.service('i18nService', ['$log', 'i18nConstants', '$rootScope',
function ($log, i18nConstants, $rootScope) {
module.service('i18nService', ['$log', '$parse', 'i18nConstants', '$rootScope',
function ($log, $parse, i18nConstants, $rootScope) {

var langCache = {
_langs: {},
Expand All @@ -59,7 +59,7 @@
fallbackLang = self.getFallbackLang();

if (lang !== self.fallback) {
return angular.merge({}, self._langs[fallbackLang],
return angular.extend({}, self._langs[fallbackLang],
self._langs[lang.toLowerCase()]);
}

Expand Down Expand Up @@ -106,7 +106,7 @@
* @methodOf ui.grid.i18n.service:i18nService
* @description Adds the languages and strings to the cache. Decorate this service to
* add more translation strings
* @param {string} lang language to add
* @param {string} langs languages to add
* @param {object} stringMaps of strings to add grouped by property names
* @example
* <pre>
Expand Down Expand Up @@ -174,32 +174,22 @@
getSafeText: function (path, lang) {
var language = lang || service.getCurrentLang(),
trans = langCache.get(language),
missing = i18nConstants.MISSING + path;
missing = i18nConstants.MISSING + path,
getter = $parse(path);

if (!trans) {
return missing;
}

var paths = path.split('.');
var current = trans;

for (var i = 0; i < paths.length; ++i) {
if (current[paths[i]] === undefined || current[paths[i]] === null) {
return missing;
} else {
current = current[paths[i]];
}
}

return current;
return getter(trans) || missing;
},

/**
* @ngdoc service
* @name setCurrentLang
* @methodOf ui.grid.i18n.service:i18nService
* @description sets the current language to use in the application
* $broadcasts and $emits the i18nConstants.UPDATE_EVENT on the $rootScope
* $broadcasts the i18nConstants.UPDATE_EVENT on the $rootScope
* @param {string} lang to set
* @example
* <pre>
Expand All @@ -210,7 +200,6 @@
if (lang) {
langCache.setCurrent(lang);
$rootScope.$broadcast(i18nConstants.UPDATE_EVENT);
$rootScope.$emit(i18nConstants.UPDATE_EVENT);
}
},

Expand Down
10 changes: 5 additions & 5 deletions src/templates/ui-grid/uiGridRenderContainer.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<div
role="presentation"
ui-grid-one-bind-id-grid="RenderContainer.gridContainerId"
ui-grid-one-bind-id-grid="containerId + '-grid-container'"
class="ui-grid-render-container"
ng-style="{ 'margin-left': RenderContainer.colContainer.getMargin('left') + 'px', 'margin-right': RenderContainer.colContainer.getMargin('right') + 'px' }">
ng-style="{ 'margin-left': colContainer.getMargin('left') + 'px', 'margin-right': colContainer.getMargin('right') + 'px' }">
<!-- All of these dom elements are replaced in place -->
<div ui-grid-header></div>
<div ui-grid-viewport></div>
<div
ng-if="RenderContainer.colContainer.needsHScrollbarPlaceholder()"
ng-if="colContainer.needsHScrollbarPlaceholder()"
class="ui-grid-scrollbar-placeholder"
ng-style="{height: RenderContainer.colContainer.grid.scrollbarHeight + 'px'}">
ng-style="{height: colContainer.grid.scrollbarHeight + 'px'}">
</div>
<ui-grid-footer
ng-if="RenderContainer.grid.options.showColumnFooter">
ng-if="grid.options.showColumnFooter">
</ui-grid-footer>
</div>

0 comments on commit cfec75c

Please sign in to comment.