Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use setTimeout/setInterval from window object with correct TS type #1252

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@jest/types": "^29.6.3",
"@lerna-lite/cli": "^3.8.0",
"@lerna-lite/publish": "^3.8.0",
"@slickgrid-universal/common": "^5.5.1",
"@slickgrid-universal/common": "^5.5.2",
"@types/jest": "^29.5.12",
"@types/node": "^22.4.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
Expand Down
12 changes: 6 additions & 6 deletions packages/aurelia-slickgrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
"@aurelia/runtime": "^2.0.0-beta.21",
"@aurelia/runtime-html": "^2.0.0-beta.21",
"@formkit/tempo": "^0.1.2",
"@slickgrid-universal/common": "~5.5.1",
"@slickgrid-universal/custom-footer-component": "~5.5.1",
"@slickgrid-universal/empty-warning-component": "~5.5.1",
"@slickgrid-universal/event-pub-sub": "~5.5.1",
"@slickgrid-universal/pagination-component": "~5.5.1",
"@slickgrid-universal/row-detail-view-plugin": "~5.5.1",
"@slickgrid-universal/common": "~5.5.2",
"@slickgrid-universal/custom-footer-component": "~5.5.2",
"@slickgrid-universal/empty-warning-component": "~5.5.2",
"@slickgrid-universal/event-pub-sub": "~5.5.2",
"@slickgrid-universal/pagination-component": "~5.5.2",
"@slickgrid-universal/row-detail-view-plugin": "~5.5.2",
"@slickgrid-universal/utils": "~5.5.1",
"dequal": "^2.0.3",
"sortablejs": "^1.15.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
// on filter changed, we need to re-render all Views
this._subscriptions.push(
this.eventPubSubService?.subscribe('onFilterChanged', this.redrawAllViewSlots.bind(this)),
this.eventPubSubService?.subscribe('onGridMenuClearAllFilters', () => setTimeout(() => this.redrawAllViewSlots())),
this.eventPubSubService?.subscribe('onGridMenuClearAllSorting', () => setTimeout(() => this.redrawAllViewSlots())),
this.eventPubSubService?.subscribe('onGridMenuClearAllFilters', () => window.setTimeout(() => this.redrawAllViewSlots())),
this.eventPubSubService?.subscribe('onGridMenuClearAllSorting', () => window.setTimeout(() => this.redrawAllViewSlots())),
);
}
}
Expand Down
20 changes: 10 additions & 10 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@
"@fnando/sparkline": "^0.3.10",
"@formkit/tempo": "^0.1.2",
"@popperjs/core": "^2.11.8",
"@slickgrid-universal/common": "^5.5.1",
"@slickgrid-universal/composite-editor-component": "^5.5.1",
"@slickgrid-universal/custom-tooltip-plugin": "^5.5.1",
"@slickgrid-universal/excel-export": "^5.5.1",
"@slickgrid-universal/graphql": "^5.5.1",
"@slickgrid-universal/odata": "^5.5.1",
"@slickgrid-universal/row-detail-view-plugin": "^5.5.1",
"@slickgrid-universal/rxjs-observable": "^5.5.1",
"@slickgrid-universal/text-export": "^5.5.1",
"@slickgrid-universal/common": "^5.5.2",
"@slickgrid-universal/composite-editor-component": "^5.5.2",
"@slickgrid-universal/custom-tooltip-plugin": "^5.5.2",
"@slickgrid-universal/excel-export": "^5.5.2",
"@slickgrid-universal/graphql": "^5.5.2",
"@slickgrid-universal/odata": "^5.5.2",
"@slickgrid-universal/row-detail-view-plugin": "^5.5.2",
"@slickgrid-universal/rxjs-observable": "^5.5.2",
"@slickgrid-universal/text-export": "^5.5.2",
"aurelia": "^2.0.0-beta.21",
"aurelia-slickgrid": "workspace:*",
"bootstrap": "^5.3.3",
"i18next": "^23.12.2",
"i18next": "^23.13.0",
"i18next-fetch-backend": "^6.0.0",
"rxjs": "^7.8.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class CustomAureliaViewModelEditor implements Editor {
this.defaultItem = itemObject;

// add a delay so that the editor has time to be enhanced (created) prior to changing the value
setTimeout(() => {
window.setTimeout(() => {
this.focus();
if (this.elmBindingContext) {
this.elmBindingContext.selectedItem = itemObject;
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/custom-inputEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class CustomInputEditor implements Editor {

this.inputElm.addEventListener('keydown', this.handleKeydown.bind(this));

setTimeout(() => {
window.setTimeout(() => {
this.inputElm.focus();
this.inputElm.select();
}, 50);
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example15.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Example15 {
clearGridStateFromLocalStorage() {
this.aureliaGrid.gridService.resetGrid(this.columnDefinitions);
this.aureliaGrid.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
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example17.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class Example17 {
// this.gridObj.setSortColumn('score', false);

// simulate a delayed search to preload the first page
setTimeout(() => this.searchChanged(this.search), 100);
window.setTimeout(() => this.searchChanged(this.search), 100);
}

defineGrid() {
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example19.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class Example19 {

// 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 packages/demo/src/examples/slickgrid/example2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class Example2 {
item.completed = !item.completed;

// simulate a backend http call and refresh the grid row after delay
setTimeout(() => {
window.setTimeout(() => {
this.aureliaGrid.gridService.updateItemById(item.id, item, { highlightRow: false });
}, 250);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example23.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class Example23 {

refreshMetrics(_e: Event, args: any) {
if (args && args.current >= 0) {
setTimeout(() => {
window.setTimeout(() => {
this.metrics = {
startTime: new Date(),
itemCount: args && args.current || 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example27.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class Example27 {
}

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
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example28.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class Example28 {
this.datasetHierarchical = tmpDatasetHierarchical;

// scroll into the position, after insertion cycle, where the item was added
setTimeout(() => {
window.setTimeout(() => {
const rowIndex = this.aureliaGrid.dataView.getRowById(popFolderItem.id) as number;
this.aureliaGrid.slickGrid.scrollRowIntoView(rowIndex + 3);
}, 10);
Expand Down
6 changes: 3 additions & 3 deletions packages/demo/src/examples/slickgrid/example3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export class Example3 {

// OR 3- use a Promise
// collectionAsync: new Promise<any>((resolve) => {
// setTimeout(() => {
// window.setTimeout(() => {
// resolve(Array.from(Array(NB_ITEMS).keys()).map(k => ({ value: k, label: k, prefix: 'Task', suffix: 'days' })));
// }, 500);
// }),
Expand All @@ -401,7 +401,7 @@ export class Example3 {
filter: {
collectionAsync: this.http.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 Expand Up @@ -452,7 +452,7 @@ export class Example3 {
const newRows = this.mockData(1, lastRowIndex);

// wrap into a timer to simulate a backend async call
setTimeout(() => {
window.setTimeout(() => {
// at any time, we can poke the "collection" property and modify it
const requisiteColumnDef = this.columnDefinitions.find((column: Column) => column.id === 'prerequisites');
if (requisiteColumnDef) {
Expand Down
4 changes: 2 additions & 2 deletions packages/demo/src/examples/slickgrid/example30.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ export class Example30 {
// 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 @@ -662,7 +662,7 @@ export class Example30 {
// 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
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example31.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class Example31 {
}
const updatedData = filteredData.slice(firstRow, firstRow + top!);

setTimeout(() => {
window.setTimeout(() => {
const backendResult: any = { query };
if (!this.isCountEnabled) {
backendResult['totalRecordCount'] = countTotalItems;
Expand Down
8 changes: 4 additions & 4 deletions packages/demo/src/examples/slickgrid/example33.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Example33 {
// 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"></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 @@ -182,7 +182,7 @@ export class Example33 {

// 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 @@ -240,7 +240,7 @@ export class Example33 {

// 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 @@ -257,7 +257,7 @@ export class Example33 {
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
10 changes: 5 additions & 5 deletions packages/demo/src/examples/slickgrid/example34.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class Example34 {
minChangePerCycle = 0;
maxChangePerCycle = 10;
refreshRate = 75;
timer: any;
timer: number;

constructor() {
// define the grid options & columns and then create the grid itself
Expand All @@ -107,7 +107,7 @@ export class Example34 {
attached() {
// populate the dataset once the grid is ready
this.getData();
setTimeout(() => {
window.setTimeout(() => {
this.startSimulation();
}, this.refreshRate);
}
Expand Down Expand Up @@ -304,11 +304,11 @@ export class Example34 {
// 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 @@ -323,7 +323,7 @@ export class Example34 {
this.aureliaGrid.slickGrid.setCellCssStyles(`highlight_${[column.id]}${row}`, hash);

// remove highlight after x amount of time
setTimeout(() => this.removeUnsavedStylingFromCell(item, column, row), this.highlightDuration);
window.setTimeout(() => this.removeUnsavedStylingFromCell(item, column, row), this.highlightDuration);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example35.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class Example35 {

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 packages/demo/src/examples/slickgrid/example38.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export class Example38 {
}
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 packages/demo/src/examples/slickgrid/example39.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export class Example39 {
},
};

setTimeout(() => {
window.setTimeout(() => {
this.graphqlQuery = this.gridOptions.backendServiceApi!.service.buildQuery();
resolve(mockedResult);
}, this.serverWaitDelay);
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class Example4 {

refreshMetrics(_e: Event, args: any) {
if (args && args.current >= 0) {
setTimeout(() => {
window.setTimeout(() => {
this.metrics = {
startTime: new Date(),
endTime: new Date(),
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/examples/slickgrid/example5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export class Example5 {
}
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 packages/demo/src/examples/slickgrid/example6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class Example6 {
};

return new Promise(resolve => {
setTimeout(() => {
window.setTimeout(() => {
this.graphqlQuery = this.graphqlService.buildQuery();
// this.graphqlQuery = this.gridOptions.backendServiceApi!.service.buildQuery();
if (this.isWithCursor) {
Expand Down Expand Up @@ -368,7 +368,7 @@ export class Example6 {
{ columnId: 'name', direction: 'asc' },
{ columnId: 'company', direction: SortDirection.DESC }
]);
setTimeout(() => {
window.setTimeout(() => {
this.aureliaGrid.paginationService?.changeItemPerPage(20);
this.aureliaGrid.paginationService?.goToPageNumber(2);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/src/my-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class MyApp {
this.addGitHubStarsLogo();

// scroll to active link route, there's probably a better way to do this but couldn't find lifecycle for it
setTimeout(() => {
window.setTimeout(() => {
const linkElm = document.querySelector('.nav-link.active');
if (linkElm) {
linkElm.scrollIntoView({ block: 'nearest' });
Expand Down
Loading