From c602bd97ee1502609fdfdf3eb9e2db1e52d37d8a Mon Sep 17 00:00:00 2001 From: Shlomi Assaf Date: Thu, 13 Jun 2019 02:37:10 +0300 Subject: [PATCH] refactor: workaround tree shakable expression --- .../drag/src/lib/column-resize/extend-table.ts | 6 +++++- .../src/lib/drag-and-drop/column/extend-table.ts | 15 +++++++++------ .../src/lib/target-events/cell-edit.directive.ts | 7 ++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/libs/ngrid/drag/src/lib/column-resize/extend-table.ts b/libs/ngrid/drag/src/lib/column-resize/extend-table.ts index d486ca8fc..eb2dad9ca 100644 --- a/libs/ngrid/drag/src/lib/column-resize/extend-table.ts +++ b/libs/ngrid/drag/src/lib/column-resize/extend-table.ts @@ -13,4 +13,8 @@ declare module '@pebula/ngrid/lib/table/columns/types' { } } -PblColumn.extendProperty('resize'); +// We trick the tree-shaker with an IIFE so it will not remove the function call expression +PblColumn.prototype.updateWidth = (function() { + PblColumn.extendProperty('resize'); + return PblColumn.prototype.updateWidth; +})(); diff --git a/libs/ngrid/drag/src/lib/drag-and-drop/column/extend-table.ts b/libs/ngrid/drag/src/lib/drag-and-drop/column/extend-table.ts index d8d1825c4..e69f2bb90 100644 --- a/libs/ngrid/drag/src/lib/drag-and-drop/column/extend-table.ts +++ b/libs/ngrid/drag/src/lib/drag-and-drop/column/extend-table.ts @@ -59,10 +59,13 @@ function checkGroupLockConstraint(this: PblColumn, column: PblColumn): boolean { return true; } -PblColumn.extendProperty('reorder'); -PblColumn.extendProperty('wontBudge'); -PblColumn.prototype.checkGroupLockConstraint = function (this: PblColumn, column: PblColumn): boolean { - return checkGroupLockConstraint.call(this, column) && checkGroupLockConstraint.call(column, this); -} +// We trick the tree-shaker with an IIFE so it will not remove the function call expression +PblColumn.prototype.checkGroupLockConstraint = (function() { + PblColumn.extendProperty('reorder'); + PblColumn.extendProperty('wontBudge'); + PblColumnGroup.extendProperty('lockColumns'); -PblColumnGroup.extendProperty('lockColumns'); + return function (this: PblColumn, column: PblColumn): boolean { + return checkGroupLockConstraint.call(this, column) && checkGroupLockConstraint.call(column, this); + }; +})(); diff --git a/libs/ngrid/target-events/src/lib/target-events/cell-edit.directive.ts b/libs/ngrid/target-events/src/lib/target-events/cell-edit.directive.ts index 5153732d2..113117828 100644 --- a/libs/ngrid/target-events/src/lib/target-events/cell-edit.directive.ts +++ b/libs/ngrid/target-events/src/lib/target-events/cell-edit.directive.ts @@ -5,7 +5,12 @@ import { UnRx } from '@pebula/utils'; import { PblColumn, PblNgridComponent, PblNgridPluginController } from '@pebula/ngrid'; import { PblNgridTargetEventsPlugin } from './target-events-plugin'; -PblColumn.extendProperty('editable'); +// We trick the tree-shaker with an IIFE so it will not remove the function call expression +PblColumn.prototype.updateWidth = (function() { + PblColumn.extendProperty('editable'); + return PblColumn.prototype.updateWidth; +})(); + @Directive({ // tslint:disable-next-line:directive-selector