Update ngrid, redefine prototypes of datatypes

Updates ngrid to the latest version
Use Object.defineProperty instead of
Number.prototype to safer extend native datatypes
This commit is contained in:
Sean Engelhardt 2020-01-23 12:38:46 +01:00
parent 7a23139f5e
commit c2ad39a2c5
3 changed files with 33 additions and 26 deletions

View File

@ -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",

View File

@ -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
});
}
}

View File

@ -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';