Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 4ef869a

Browse files
committed
refactor(#1591): resolve shadowed variables
1 parent 775d17d commit 4ef869a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/angular-datatables.directive.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ export class DataTableDirective implements OnDestroy, OnInit {
6969
this.dtOptions = dtOptions;
7070
}
7171
this.dtInstance = new Promise((resolve, reject) => {
72-
Promise.resolve(this.dtOptions).then(dtOptions => {
72+
Promise.resolve(this.dtOptions).then(resolvedDTOptions => {
7373
// validate object
74-
const isTableEmpty = Object.keys(dtOptions).length == 0 && $('tbody tr', this.el.nativeElement).length == 0;
74+
const isTableEmpty = Object.keys(resolvedDTOptions).length === 0 && $('tbody tr', this.el.nativeElement).length === 0;
7575
if (isTableEmpty) {
7676
reject('Both the table and dtOptions cannot be empty');
7777
return;
@@ -81,15 +81,15 @@ export class DataTableDirective implements OnDestroy, OnInit {
8181
// Assign DT properties here
8282
let options: ADTSettings = {
8383
rowCallback: (row, data, index) => {
84-
if (dtOptions.columns) {
85-
const columns = dtOptions.columns;
84+
if (resolvedDTOptions.columns) {
85+
const columns = resolvedDTOptions.columns;
8686
// Filter columns with pipe declared
8787
const colsWithPipe = columns.filter(x => x.ngPipeInstance && !x.ngTemplateRef);
8888
// Iterate
8989
colsWithPipe.forEach(el => {
9090
const pipe = el.ngPipeInstance;
9191
// find index of column using `data` attr
92-
const i = columns.findIndex(e => e.data == el.data);
92+
const i = columns.findIndex(e => e.data === el.data);
9393
// get <td> element which holds data using index
9494
const rowFromCol = row.childNodes.item(i);
9595
// Transform data with Pipe
@@ -104,8 +104,8 @@ export class DataTableDirective implements OnDestroy, OnInit {
104104
colsWithTemplate.forEach(el => {
105105
const { ref, context } = el.ngTemplateRef;
106106
// get <td> element which holds data using index
107-
const index = columns.findIndex(e => e.data == el.data);
108-
const cellFromIndex = row.childNodes.item(index);
107+
const i = columns.findIndex(e => e.data === el.data);
108+
const cellFromIndex = row.childNodes.item(i);
109109
// render onto DOM
110110
// finalize context to be sent to user
111111
const _context = Object.assign({}, context, context?.userData, {
@@ -117,13 +117,13 @@ export class DataTableDirective implements OnDestroy, OnInit {
117117
}
118118

119119
// run user specified row callback if provided.
120-
if (this.dtOptions.rowCallback) {
121-
this.dtOptions.rowCallback(row, data, index);
120+
if (resolvedDTOptions.rowCallback) {
121+
resolvedDTOptions.rowCallback(row, data, index);
122122
}
123123
}
124124
};
125125
// merge user's config with ours
126-
options = Object.assign({}, dtOptions, options);
126+
options = Object.assign({}, resolvedDTOptions, options);
127127
this.dt = $(this.el.nativeElement).DataTable(options);
128128
resolve(this.dt);
129129
});

0 commit comments

Comments
 (0)