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-pwa/local-storage": "~8.2.1",
"@ngx-translate/core": "~11.0.1", "@ngx-translate/core": "~11.0.1",
"@ngx-translate/http-loader": "^4.0.0", "@ngx-translate/http-loader": "^4.0.0",
"@pebula/ngrid": "1.0.0-rc.9", "@pebula/ngrid": "1.0.0-rc.16",
"@pebula/ngrid-material": "1.0.0-rc.9", "@pebula/ngrid-material": "1.0.0-rc.16",
"@pebula/utils": "1.0.0", "@pebula/utils": "1.0.2",
"@tinymce/tinymce-angular": "^3.2.0", "@tinymce/tinymce-angular": "^3.2.0",
"acorn": "^7.0.0", "acorn": "^7.0.0",
"core-js": "^3.2.1", "core-js": "^3.2.1",

View File

@ -112,11 +112,11 @@ export class AppComponent {
* Will add a whitespace after a comma and shorten the output to * Will add a whitespace after a comma and shorten the output to
* three strings. * three strings.
* *
* TODO: There might be a better place for overloading functions than app.component * TODO: Should be renamed
* TODO: Overloading can be extended to more functions.
*/ */
private overloadArrayToString(): void { private overloadArrayToString(): void {
Array.prototype.toString = function(): string { Object.defineProperty(Array.prototype, 'toString', {
value: function(): string {
let string = ''; let string = '';
const iterations = Math.min(this.length, 3); const iterations = Math.min(this.length, 3);
@ -132,7 +132,9 @@ export class AppComponent {
} }
} }
return string; return string;
}; },
enumerable: false
});
} }
/** /**
@ -142,9 +144,11 @@ export class AppComponent {
private overloadFlatMap(): void { private overloadFlatMap(): void {
const concat = (x: any, y: any) => x.concat(y); const concat = (x: any, y: any) => x.concat(y);
const flatMap = (f: any, xs: any) => xs.map(f).reduce(concat, []); 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. * TODO: Remove this, if the remainder operation is changed to modulo.
*/ */
private overloadModulo(): void { private overloadModulo(): void {
Number.prototype.modulo = function(n: number): number { Object.defineProperty(Number.prototype, 'modulo', {
value: function(n: number): number {
return ((this % n) + n) % n; return ((this % n) + n) % n;
}; },
enumerable: false
});
} }
} }

View File

@ -13,7 +13,7 @@ import {
import { NavigationStart, Router } from '@angular/router'; import { NavigationStart, Router } from '@angular/router';
import { columnFactory, createDS, DataSourcePredicate, PblDataSource, PblNgridComponent } from '@pebula/ngrid'; 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 { PblNgridDataMatrixRow } from '@pebula/ngrid/target-events';
import { Observable, Subscription } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
import { distinctUntilChanged, filter } from 'rxjs/operators'; import { distinctUntilChanged, filter } from 'rxjs/operators';