Skip to content

Commit

Permalink
fix: use setTimeout/setInterval from window object with correct TS type
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Aug 17, 2024
1 parent 7e39922 commit 1050774
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/app/examples/custom-inputEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class CustomInputEditor implements Editor {
this.inputElm.addEventListener('focusout', this.save.bind(this));
}

setTimeout(() => {
window.setTimeout(() => {
this.inputElm.focus();
this.inputElm.select();
}, 50);
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-base-row-editing.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class GridBaseRowEditingComponent implements OnInit {

function fakeFetch(_input: string | URL | Request, _init?: RequestInit | undefined): Promise<Response> {
return new Promise((resolve) => {
setTimeout(() => {
window.setTimeout(() => {
resolve(new Response(JSON.stringify({ status: 200, message: 'success' })));
// reduces the delay for automated Cypress tests
}, (window as any).Cypress ? 10 : 500);
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-clientside.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class GridClientSideComponent implements OnInit {

refreshMetrics(e: Event, args: any) {
if (args && args.current >= 0) {
setTimeout(() => {
window.setTimeout(() => {
this.metrics = {
startTime: new Date(),
endTime: new Date(),
Expand Down
4 changes: 2 additions & 2 deletions src/app/examples/grid-composite-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
// when processing a mass update or mass selection
if (modalType === 'mass-update' || modalType === 'mass-selection') {
return new Promise((resolve, reject) => {
setTimeout(() => {
window.setTimeout(() => {
if (formValues.percentComplete >= 50) {
resolve(true);
} else {
Expand All @@ -663,7 +663,7 @@ export class GridCompositeEditorComponent implements OnDestroy, OnInit {
// we'll just apply the change without any rejection from the server and
// note that we also have access to the "dataContext" which is only available for these modal
console.log(`${modalType} item data context`, dataContext);
return new Promise(resolve => setTimeout(() => resolve(true), serverResponseDelay));
return new Promise(resolve => window.setTimeout(() => resolve(true), serverResponseDelay));
}
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/app/examples/grid-custom-tooltip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class GridCustomTooltipComponent implements OnInit {
// you will need to provide an `asyncPost` function returning a Promise and also `asyncPostFormatter` formatter to display the result once the Promise resolves
formatter: () => `<div><span class="mdi mdi-load mdi-spin-1s"></span> loading...</div>`,
asyncProcess: () => new Promise(resolve => {
setTimeout(() => resolve({ ratio: Math.random() * 10 / 10, lifespan: Math.random() * 100 }), this.serverApiDelay);
window.setTimeout(() => resolve({ ratio: Math.random() * 10 / 10, lifespan: Math.random() * 100 }), this.serverApiDelay);
}),
asyncPostFormatter: this.tooltipTaskAsyncFormatter as Formatter,

Expand Down Expand Up @@ -180,7 +180,7 @@ export class GridCustomTooltipComponent implements OnInit {

// 2- delay the opening by a simple Promise and `setTimeout`
asyncProcess: () => new Promise(resolve => {
setTimeout(() => resolve({}), this.serverApiDelay); // delayed by half a second
window.setTimeout(() => resolve({}), this.serverApiDelay); // delayed by half a second
}),
asyncPostFormatter: this.tooltipFormatter.bind(this) as Formatter,
},
Expand Down Expand Up @@ -235,7 +235,7 @@ export class GridCustomTooltipComponent implements OnInit {

// OR 2- use a Promise
collectionAsync: new Promise<any>((resolve) => {
setTimeout(() => {
window.setTimeout(() => {
resolve(Array.from(Array(this.dataset.length).keys()).map(k => ({ value: k, label: k, prefix: 'Task', suffix: 'days' })));
}, 500);
}),
Expand All @@ -252,7 +252,7 @@ export class GridCustomTooltipComponent implements OnInit {
filter: {
// collectionAsync: fetch(URL_SAMPLE_COLLECTION_DATA),
collectionAsync: new Promise((resolve) => {
setTimeout(() => {
window.setTimeout(() => {
resolve(Array.from(Array(this.dataset.length).keys()).map(k => ({ value: k, label: `Task ${k}` })));
});
}),
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class GridEditorComponent implements OnInit {
const newRows = this.mockData(1, lastRowIndex);

// wrap into a timer to simulate a backend async call
setTimeout(() => {
window.setTimeout(() => {
const requisiteColumnDef = this.columnDefinitions.find((column: Column) => column.id === 'prerequisites');
if (requisiteColumnDef) {
const filterCollectionAsync = requisiteColumnDef.filter!.collectionAsync;
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-formatter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class GridFormatterComponent implements OnInit {
item.completed = !item.completed;

// simulate a backend http call and refresh the grid row after delay
setTimeout(() => {
window.setTimeout(() => {
this.angularGrid.gridService.updateItemById(item.id, item, { highlightRow: false });
}, 250);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/examples/grid-graphql.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class GridGraphqlComponent implements OnInit, OnDestroy {
};

return new Promise(resolve => {
setTimeout(() => {
window.setTimeout(() => {
this.graphqlQuery = this.angularGrid.backendService!.buildQuery();
if (this.isWithCursor) {
// When using cursor pagination, the pagination service needs to be updated with the PageInfo data from the latest request
Expand Down Expand Up @@ -388,7 +388,7 @@ export class GridGraphqlComponent implements OnInit, OnDestroy {
{ columnId: 'name', direction: 'asc' },
{ columnId: 'company', direction: SortDirection.DESC }
]);
setTimeout(() => {
window.setTimeout(() => {
this.angularGrid.paginationService?.changeItemPerPage(20);
this.angularGrid.paginationService?.goToPageNumber(2);
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-infinite-graphql.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class GridInfiniteGraphqlComponent implements OnInit, OnDestroy {
},
};

setTimeout(() => {
window.setTimeout(() => {
this.graphqlQuery = this.gridOptions.backendServiceApi!.service.buildQuery();
resolve(mockedResult);
}, this.serverWaitDelay);
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-infinite-odata.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export class GridInfiniteOdataComponent implements OnInit {
}
const updatedData = filteredData.slice(firstRow, firstRow + top);

setTimeout(() => {
window.setTimeout(() => {
const backendResult: any = { query };
backendResult['value'] = updatedData;
backendResult['@odata.count'] = countTotalItems;
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-odata.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export class GridOdataComponent implements OnInit {
}
const updatedData = filteredData.slice(firstRow, firstRow + top!);

setTimeout(() => {
window.setTimeout(() => {
const backendResult: any = { query };
if (!this.isCountEnabled) {
backendResult['totalRecordCount'] = countTotalItems;
Expand Down
4 changes: 2 additions & 2 deletions src/app/examples/grid-range.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ export class GridRangeComponent implements OnInit, OnDestroy {
}

refreshMetrics(_e: Event, args: any) {
if (args && args.current >= 0) {
setTimeout(() => {
if (args?.current >= 0) {
window.setTimeout(() => {
this.metrics = {
startTime: new Date(),
itemCount: args && args.current || 0,
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-rowdetail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class GridRowDetailComponent implements OnDestroy, OnInit {

// fill the template on async delay
return new Promise((resolve) => {
setTimeout(() => {
window.setTimeout(() => {
const itemDetail = item;

// let's add some extra properties to our item for a better async simulation
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-state.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class GridStateComponent implements OnInit, OnDestroy {
clearGridStateFromLocalStorage() {
this.angularGrid.gridService.resetGrid(this.columnDefinitions);
this.angularGrid.paginationService!.changeItemPerPage(DEFAULT_PAGE_SIZE);
setTimeout(() => localStorage[LOCAL_STORAGE_KEY] = null);
window.setTimeout(() => localStorage[LOCAL_STORAGE_KEY] = null);
}

/* Define grid Options and Columns */
Expand Down
10 changes: 5 additions & 5 deletions src/app/examples/grid-trading.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ export class GridTradingComponent implements OnDestroy, OnInit {
minChangePerCycle = 0;
maxChangePerCycle = 10;
refreshRate = 75;
timer: any;
timer?: number;

ngOnInit(): void {
this.defineGrid();

// mock a dataset
this.dataset = this.loadData(NB_ROWS);

setTimeout(() => {
window.setTimeout(() => {
this.startSimulation();
}, this.refreshRate);
}
Expand Down Expand Up @@ -310,11 +310,11 @@ export class GridTradingComponent implements OnDestroy, OnInit {
// but the cell highlight actually does that for us so we can skip it
}

this.timer = setTimeout(this.startSimulation.bind(this), this.refreshRate || 0);
this.timer = window.setTimeout(this.startSimulation.bind(this), this.refreshRate || 0);
}

stopSimulation() {
clearTimeout(this.timer);
window.clearTimeout(this.timer);
}

findColumnById(columnName: string): Column {
Expand All @@ -329,7 +329,7 @@ export class GridTradingComponent implements OnDestroy, OnInit {
this.angularGrid.slickGrid.setCellCssStyles(`highlight_${[column.id]}${row}`, hash);

// remove highlight after x amount of time
setTimeout(() => this.removeCellStyling(item, column, row), this.highlightDuration);
window.setTimeout(() => this.removeCellStyling(item, column, row), this.highlightDuration);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-tree-data-hierarchical.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class GridTreeDataHierarchicalComponent implements OnInit {
this.datasetHierarchical = tmpDatasetHierarchical;

// scroll into the position, after insertion cycle, where the item was added
setTimeout(() => {
window.setTimeout(() => {
const rowIndex = this.dataViewObj.getRowById(popFolderItem.id);
this.gridObj.scrollRowIntoView(rowIndex + 3);
}, 10);
Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/grid-tree-data-parent-child.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class GridTreeDataParentChildComponent implements OnInit {
}

hideSpinner() {
setTimeout(() => this.loadingClass = '', 200); // delay the hide spinner a bit to avoid show/hide too quickly
window.setTimeout(() => this.loadingClass = '', 200); // delay the hide spinner a bit to avoid show/hide too quickly
}

showSpinner() {
Expand Down
4 changes: 2 additions & 2 deletions src/app/examples/swt-common-grid-test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class SwtCommonGridTestComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
this.logger.info('method [ngAfterViewInit] - START');

setTimeout(() => {
window.setTimeout(() => {
// Init datagrid example:
this.commonGridPag.processing = true;

Expand Down Expand Up @@ -92,7 +92,7 @@ export class SwtCommonGridTestComponent implements OnInit, AfterViewInit {
this.commonGridPag.processing = false;
}
);*/
setTimeout(() => {
window.setTimeout(() => {
this.commonGrid.gridData = data_sample.pagination_samples.grid.rows;
this.commonGridPag.pageCount = data_sample.pagination_samples.grid.rows.maxpage;
}, 750);
Expand Down
6 changes: 3 additions & 3 deletions src/app/examples/swt-common-grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { SwtCommonGridPaginationComponent } from './swt-common-grid-pagination.c
* @author Saber Chebka, saber.chebka@gmail.com
*/

let timer: any;
let timer: number | undefined;
const DEFAULT_FILTER_TYPING_DEBOUNCE = 750;

@Component({
Expand Down Expand Up @@ -338,9 +338,9 @@ export class SwtCommonGridComponent implements OnInit, AfterViewInit, BackendSer
let timing = 0;
if (event && (event.type === 'keyup' || event.type === 'keydown')) {
timing = DEFAULT_FILTER_TYPING_DEBOUNCE;
clearTimeout(timer);
window.clearTimeout(timer);
}
timer = setTimeout(() => {
timer = window.setTimeout(() => {
this.filteredGridColumns = '';
for (const column of this.columnDefinitions) {
if (column.field in args.columnFilters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
// on filter changed, we need to re-render all Views
this._subscriptions.push(
this.eventPubSubService?.subscribe('onFilterChanged', this.redrawAllViewComponents.bind(this)),
this.eventPubSubService?.subscribe('onGridMenuClearAllFilters', () => setTimeout(() => this.redrawAllViewComponents())),
this.eventPubSubService?.subscribe('onGridMenuClearAllSorting', () => setTimeout(() => this.redrawAllViewComponents())),
this.eventPubSubService?.subscribe('onGridMenuClearAllFilters', () => window.setTimeout(() => this.redrawAllViewComponents())),
this.eventPubSubService?.subscribe('onGridMenuClearAllSorting', () => window.setTimeout(() => this.redrawAllViewComponents())),
);
}
}
Expand Down

0 comments on commit 1050774

Please sign in to comment.