From c2ad39a2c5c12ec28d1d17e14603d20f462d04ff Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Thu, 23 Jan 2020 12:38:46 +0100 Subject: [PATCH] Update ngrid, redefine prototypes of datatypes Updates ngrid to the latest version Use Object.defineProperty instead of Number.prototype to safer extend native datatypes --- client/package.json | 6 +-- client/src/app/app.component.ts | 51 +++++++++++-------- .../list-view-table.component.ts | 2 +- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/client/package.json b/client/package.json index 02ca8cce0..8624fa96d 100644 --- a/client/package.json +++ b/client/package.json @@ -48,9 +48,9 @@ "@ngx-pwa/local-storage": "~8.2.1", "@ngx-translate/core": "~11.0.1", "@ngx-translate/http-loader": "^4.0.0", - "@pebula/ngrid": "1.0.0-rc.9", - "@pebula/ngrid-material": "1.0.0-rc.9", - "@pebula/utils": "1.0.0", + "@pebula/ngrid": "1.0.0-rc.16", + "@pebula/ngrid-material": "1.0.0-rc.16", + "@pebula/utils": "1.0.2", "@tinymce/tinymce-angular": "^3.2.0", "acorn": "^7.0.0", "core-js": "^3.2.1", diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index 2054622c8..b12f4e98c 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -112,27 +112,29 @@ export class AppComponent { * Will add a whitespace after a comma and shorten the output to * three strings. * - * TODO: There might be a better place for overloading functions than app.component - * TODO: Overloading can be extended to more functions. + * TODO: Should be renamed */ private overloadArrayToString(): void { - Array.prototype.toString = function(): string { - let string = ''; - const iterations = Math.min(this.length, 3); + Object.defineProperty(Array.prototype, 'toString', { + value: function(): string { + let string = ''; + const iterations = Math.min(this.length, 3); - for (let i = 0; i <= iterations; i++) { - if (i < iterations) { - string += this[i]; - } + for (let i = 0; i <= iterations; i++) { + if (i < iterations) { + string += this[i]; + } - if (i < iterations - 1) { - string += ', '; - } else if (i === iterations && this.length > iterations) { - string += ', ...'; + if (i < iterations - 1) { + string += ', '; + } else if (i === iterations && this.length > iterations) { + string += ', ...'; + } } - } - return string; - }; + return string; + }, + enumerable: false + }); } /** @@ -142,9 +144,11 @@ export class AppComponent { private overloadFlatMap(): void { const concat = (x: any, y: any) => x.concat(y); const flatMap = (f: any, xs: any) => xs.map(f).reduce(concat, []); - Array.prototype.flatMap = function(f: any): any[] { - return flatMap(f, this); - }; + + Object.defineProperty(Array.prototype, 'flatMap', { + value: flatMap, + enumerable: false + }); } /** @@ -152,8 +156,11 @@ export class AppComponent { * TODO: Remove this, if the remainder operation is changed to modulo. */ private overloadModulo(): void { - Number.prototype.modulo = function(n: number): number { - return ((this % n) + n) % n; - }; + Object.defineProperty(Number.prototype, 'modulo', { + value: function(n: number): number { + return ((this % n) + n) % n; + }, + enumerable: false + }); } } diff --git a/client/src/app/shared/components/list-view-table/list-view-table.component.ts b/client/src/app/shared/components/list-view-table/list-view-table.component.ts index 7f42f65e8..c3524e0b4 100644 --- a/client/src/app/shared/components/list-view-table/list-view-table.component.ts +++ b/client/src/app/shared/components/list-view-table/list-view-table.component.ts @@ -13,7 +13,7 @@ import { import { NavigationStart, Router } from '@angular/router'; import { columnFactory, createDS, DataSourcePredicate, PblDataSource, PblNgridComponent } from '@pebula/ngrid'; -import { PblColumnDefinition, PblColumnFactory, PblNgridColumnSet } from '@pebula/ngrid/lib/table'; +import { PblColumnDefinition, PblColumnFactory, PblNgridColumnSet } from '@pebula/ngrid/lib/grid'; import { PblNgridDataMatrixRow } from '@pebula/ngrid/target-events'; import { Observable, Subscription } from 'rxjs'; import { distinctUntilChanged, filter } from 'rxjs/operators';