Skip to content

Commit

Permalink
AG-2296 - calling setTimeout, setInterval, clearInterval, clearTimeou…
Browse files Browse the repository at this point in the history
…t as window method
  • Loading branch information
gportela85 committed Nov 30, 2018
1 parent d10f99a commit 30d1727
Show file tree
Hide file tree
Showing 56 changed files with 115 additions and 113 deletions.
2 changes: 1 addition & 1 deletion packages/ag-grid-angular/src/ng2FrameworkFactory.ts
Expand Up @@ -16,7 +16,7 @@ export class Ng2FrameworkFactory implements IFrameworkFactory {

public setTimeout(action: any, timeout?: any): void {
this._ngZone.runOutsideAngular(() => {
setTimeout(() => {
window.setTimeout(() => {
action();
}, timeout);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/ag-grid-community/src/ts/baseFrameworkFactory.ts
Expand Up @@ -41,6 +41,6 @@ export class BaseFrameworkFactory implements IFrameworkFactory {
}

public setTimeout(action: any, timeout?: any): void {
setTimeout(action, timeout);
window.setTimeout(action, timeout);
}
}
Expand Up @@ -447,9 +447,9 @@ export class ColumnController {
for (let i = 0; i < childColumns.length; i++) {
const child = childColumns[i];
if (child instanceof Column) {
result.push(child as Column);
result.push(child);
} else if (child instanceof OriginalColumnGroup) {
recursiveFindColumns((child as OriginalColumnGroup).getChildren());
recursiveFindColumns(child.getChildren());
}
}
}
Expand Down Expand Up @@ -1569,12 +1569,12 @@ export class ColumnController {
}

const primaryColumnState: ColumnState[]
= this.primaryColumns.map(this.createStateItemFromColumn.bind(this)) as ColumnState[];
= this.primaryColumns.map(this.createStateItemFromColumn.bind(this));

const groupAutoColumnState: ColumnState[]
= this.groupAutoColumns
// if groupAutoCols, then include them
? this.groupAutoColumns.map(this.createStateItemFromColumn.bind(this)) as ColumnState[]
? this.groupAutoColumns.map(this.createStateItemFromColumn.bind(this))
// otherwise no
: [];

Expand Down Expand Up @@ -2096,7 +2096,7 @@ export class ColumnController {
}

if (aggFuncFound) {
const aggFuncString = (typeof aggFunc === 'string') ? aggFunc as string : 'func';
const aggFuncString = (typeof aggFunc === 'string') ? aggFunc : 'func';
const localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc();
const aggFuncStringTranslated = localeTextFunc(aggFuncString, aggFuncString);
return `${aggFuncStringTranslated}(${headerName})`;
Expand All @@ -2123,7 +2123,7 @@ export class ColumnController {

this.columnUtils.depthFirstAllColumnTreeSearch(allColumnGroups, (child: ColumnGroupChild) => {
if (child instanceof ColumnGroup) {
const columnGroup = child as ColumnGroup;
const columnGroup = child;
let matched: boolean;
if (checkInstanceId) {
matched = colId === columnGroup.getGroupId() && instanceId === columnGroup.getInstanceId();
Expand Down Expand Up @@ -2260,7 +2260,7 @@ export class ColumnController {
const columnGroupState: { groupId: string, open: boolean }[] = [];
this.columnUtils.depthFirstOriginalTreeSearch(this.gridBalancedTree, node => {
if (node instanceof OriginalColumnGroup) {
const originalColumnGroup = node as OriginalColumnGroup;
const originalColumnGroup = node;
columnGroupState.push({
groupId: originalColumnGroup.getGroupId(),
open: originalColumnGroup.isExpanded()
Expand Down Expand Up @@ -2312,16 +2312,16 @@ export class ColumnController {
public setColumnGroupOpened(key: OriginalColumnGroup | string | undefined, newValue: boolean, source: ColumnEventType = "api"): void {
let keyAsString: string;
if (key instanceof OriginalColumnGroup) {
keyAsString = (key as OriginalColumnGroup).getId();
keyAsString = key.getId();
} else {
keyAsString = key as string;
keyAsString = key;
}
this.setColumnGroupState([{groupId: keyAsString, open: newValue}], source);
}

public getOriginalColumnGroup(key: OriginalColumnGroup | string): OriginalColumnGroup | null {
if (key instanceof OriginalColumnGroup) {
return key as OriginalColumnGroup;
return key;
}

if (typeof key !== 'string') {
Expand All @@ -2332,7 +2332,7 @@ export class ColumnController {
let res: OriginalColumnGroup | null = null;
this.columnUtils.depthFirstOriginalTreeSearch(this.gridBalancedTree, node => {
if (node instanceof OriginalColumnGroup) {
const originalColumnGroup = node as OriginalColumnGroup;
const originalColumnGroup = node;
if (originalColumnGroup.getId() === key) {
res = originalColumnGroup;
}
Expand Down Expand Up @@ -2703,7 +2703,7 @@ export class ColumnController {
[this.displayedLeftColumnTree, this.displayedRightColumnTree, this.displayedCentreColumnTree].forEach(columns => {
columns.forEach(column => {
if (column instanceof ColumnGroup) {
const columnGroup = column as ColumnGroup;
const columnGroup = column;
columnGroup.checkLeft();
}
});
Expand Down Expand Up @@ -2919,7 +2919,7 @@ export class ColumnController {
const allColumnGroups = this.getAllDisplayedColumnGroups();
this.columnUtils.depthFirstAllColumnTreeSearch(allColumnGroups, child => {
if (child instanceof ColumnGroup) {
const columnGroup = child as ColumnGroup;
const columnGroup = child;
columnGroup.calculateDisplayedColumns();
}
});
Expand Down
Expand Up @@ -48,7 +48,7 @@ export class ColumnFactory {

this.columnUtils.depthFirstOriginalTreeSearch(res, (child: OriginalColumnGroupChild) => {
if (child instanceof OriginalColumnGroup) {
(child as OriginalColumnGroup).setupExpandable();
child.setupExpandable();
}
});

Expand Down Expand Up @@ -110,7 +110,7 @@ export class ColumnFactory {
// for columns we need to pad
unbalancedTree.forEach((child: OriginalColumnGroupChild) => {
if (child instanceof OriginalColumnGroup) {
const originalGroup = child as OriginalColumnGroup;
const originalGroup = child;
const newChildren = this.balanceColumnTree(originalGroup.getChildren(),
currentDept + 1, columnDept, columnKeyCreator);
originalGroup.setChildren(newChildren);
Expand All @@ -137,7 +137,7 @@ export class ColumnFactory {
for (let i = 0; i < treeChildren.length; i++) {
const abstractColumn = treeChildren[i];
if (abstractColumn instanceof OriginalColumnGroup) {
const originalGroup = abstractColumn as OriginalColumnGroup;
const originalGroup = abstractColumn;
const newDept = this.findMaxDept(originalGroup.getChildren(), dept + 1);
if (maxDeptThisLevel < newDept) {
maxDeptThisLevel = newDept;
Expand Down
Expand Up @@ -49,7 +49,7 @@ export class ColumnUtils {
}
const node = balancedColumnTree[i];
if (node instanceof OriginalColumnGroup) {
const nextNode = node as OriginalColumnGroup;
const nextNode = node;
recursePath(nextNode.getChildren(), dept + 1);
result[dept] = node;
} else {
Expand Down Expand Up @@ -102,7 +102,7 @@ export class ColumnUtils {

tree.forEach((child: OriginalColumnGroupChild) => {
if (child instanceof OriginalColumnGroup) {
this.depthFirstOriginalTreeSearch((child as OriginalColumnGroup).getChildren(), callback);
this.depthFirstOriginalTreeSearch(child.getChildren(), callback);
}
callback(child);
});
Expand All @@ -115,7 +115,7 @@ export class ColumnUtils {

tree.forEach((child: ColumnGroupChild) => {
if (child instanceof ColumnGroup) {
this.depthFirstAllColumnTreeSearch((child as ColumnGroup).getChildren(), callback);
this.depthFirstAllColumnTreeSearch(child.getChildren(), callback);
}
callback(child);
});
Expand All @@ -128,7 +128,7 @@ export class ColumnUtils {

tree.forEach((child: ColumnGroupChild) => {
if (child instanceof ColumnGroup) {
this.depthFirstDisplayedColumnTreeSearch((child as ColumnGroup).getDisplayedChildren(), callback);
this.depthFirstDisplayedColumnTreeSearch(child.getDisplayedChildren(), callback);
}
callback(child);
});
Expand Down
Expand Up @@ -116,7 +116,7 @@ export class DisplayedGroupCreator {
const recursive = (columnsOrGroups: ColumnGroupChild[]) => {
columnsOrGroups.forEach(columnOrGroup => {
if (columnOrGroup instanceof ColumnGroup) {
const columnGroup = columnOrGroup as ColumnGroup;
const columnGroup = columnOrGroup;
result[columnOrGroup.getUniqueId()] = columnGroup;
recursive(columnGroup.getChildren());
}
Expand All @@ -134,7 +134,7 @@ export class DisplayedGroupCreator {
columnsOrGroups.forEach(columnsOrGroup => {
columnsOrGroup.setParent(parent);
if (columnsOrGroup instanceof ColumnGroup) {
const columnGroup = columnsOrGroup as ColumnGroup;
const columnGroup = columnsOrGroup;
this.setupParentsIntoColumns(columnGroup.getChildren(), columnGroup);
}
});
Expand Down Expand Up @@ -193,7 +193,7 @@ export class DisplayedGroupCreator {
}
const node = balancedColumnTree[i];
if (node instanceof OriginalColumnGroup) {
const nextNode = node as OriginalColumnGroup;
const nextNode = node;
recursePath(nextNode.getChildren(), dept + 1);
result[dept] = node;
} else {
Expand Down
Expand Up @@ -35,7 +35,7 @@ export function initialiseAgGridWithWebComponents() {
});
});

const agGridProtoNoType = AgileGridProto as any;
const agGridProtoNoType = AgileGridProto;

agGridProtoNoType.__agGridSetProperty = function(key: string, value: any) {
if (!this.__attributes) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ag-grid-community/src/ts/context/beanStub.ts
Expand Up @@ -36,7 +36,7 @@ export class BeanStub implements IEventEmitter {
}

public dispatchEventAsync(event: AgEvent): void {
setTimeout(() => this.dispatchEvent(event), 0);
window.setTimeout(() => this.dispatchEvent(event), 0);
}

public dispatchEvent<T extends AgEvent>(event: T): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/ag-grid-community/src/ts/eventService.ts
Expand Up @@ -156,7 +156,7 @@ export class EventService implements IEventEmitter {
// set to 'true' so it will know it's already scheduled for subsequent calls.
if (!this.scheduled) {
// if not scheduled, schedule one
setTimeout(this.flushAsyncQueue.bind(this), 0);
window.setTimeout(this.flushAsyncQueue.bind(this), 0);
// mark that it is scheduled
this.scheduled = true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ag-grid-community/src/ts/filter/filterManager.ts
Expand Up @@ -508,7 +508,7 @@ export class FilterManager {
if (filterWrapper.scope) {
const compiledElement = this.$compile(eFilterGui)(filterWrapper.scope);
filterWrapper.compiledElement = compiledElement;
setTimeout(() => filterWrapper.scope.$apply(), 0);
window.setTimeout(() => filterWrapper.scope.$apply(), 0);
}

filterWrapper.guiPromise.resolve(eFilterGui);
Expand Down
4 changes: 2 additions & 2 deletions packages/ag-grid-community/src/ts/gridApi.ts
Expand Up @@ -363,7 +363,7 @@ export class GridApi {
const start = (new Date()).getTime();
that.rowRenderer.redrawAfterModelUpdate();
const endProcessing = (new Date()).getTime();
setTimeout(() => {
window.setTimeout(() => {
const endReflow = (new Date()).getTime();
const durationProcessing = endProcessing - start;
const durationReflow = endReflow - endProcessing;
Expand All @@ -376,7 +376,7 @@ export class GridApi {

if (iterationCount < count) {
// wait for 1s between tests
setTimeout(doOneIteration, 1000);
window.setTimeout(doOneIteration, 1000);
} else {
finish();
}
Expand Down
8 changes: 4 additions & 4 deletions packages/ag-grid-community/src/ts/gridPanel/gridPanel.ts
Expand Up @@ -376,7 +376,7 @@ export class GridPanel extends Component {
// only need to do one apply at a time
if (applyTriggered) { return; }
applyTriggered = true; // mark 'need apply' to true
setTimeout(() => {
window.setTimeout(() => {
applyTriggered = false;
this.$scope.$apply();
}, 0);
Expand Down Expand Up @@ -958,15 +958,15 @@ export class GridPanel extends Component {
}

if (nextTimeout === undefined) {
setTimeout(() => {
window.setTimeout(() => {
this.sizeColumnsToFit(100);
}, 0);
} else if (nextTimeout === 100) {
setTimeout(() => {
window.setTimeout(() => {
this.sizeColumnsToFit(500);
}, 100);
} else if (nextTimeout === 500) {
setTimeout(() => {
window.setTimeout(() => {
this.sizeColumnsToFit(-1);
}, 500);
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/ag-grid-community/src/ts/gridPanel/rowDragFeature.ts
Expand Up @@ -135,13 +135,13 @@ export class RowDragFeature implements DropTarget {
private ensureIntervalStarted(): void {
if (!this.movingIntervalId) {
this.intervalCount = 0;
this.movingIntervalId = setInterval(this.moveInterval.bind(this), 100);
this.movingIntervalId = window.setInterval(this.moveInterval.bind(this), 100);
}
}

private ensureIntervalCleared(): void {
if (this.moveInterval) {
clearInterval(this.movingIntervalId);
window.clearInterval(this.movingIntervalId);
this.movingIntervalId = null;
}
}
Expand Down
Expand Up @@ -342,7 +342,7 @@ export class MoveColumnController implements DropListener {
if (!this.movingIntervalId) {
this.intervalCount = 0;
this.failedMoveAttempts = 0;
this.movingIntervalId = setInterval(this.moveInterval.bind(this), 100);
this.movingIntervalId = window.setInterval(this.moveInterval.bind(this), 100);
if (this.needToMoveLeft) {
this.dragAndDropService.setGhostIcon(DragAndDropService.ICON_LEFT, true);
} else {
Expand All @@ -353,7 +353,7 @@ export class MoveColumnController implements DropListener {

private ensureIntervalCleared(): void {
if (this.moveInterval) {
clearInterval(this.movingIntervalId);
window.clearInterval(this.movingIntervalId);
this.movingIntervalId = null;
this.dragAndDropService.setGhostIcon(DragAndDropService.ICON_MOVE);
}
Expand Down
Expand Up @@ -132,7 +132,7 @@ export class AnimationFrameService {
} else if (window.webkitRequestAnimationFrame) {
window.webkitRequestAnimationFrame(callback);
} else {
setTimeout(callback, 0);
window.setTimeout(callback, 0);
}
}

Expand Down
Expand Up @@ -74,7 +74,7 @@ export class AutoWidthCalculator {
// find the rendered header cell
this.headerRootComp.forEachHeaderElement(headerElement => {
if (headerElement instanceof HeaderWrapperComp) {
const headerWrapperComp = headerElement as HeaderWrapperComp;
const headerWrapperComp = headerElement;
if (headerWrapperComp.getColumn() === column) {
comp = headerWrapperComp;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/ag-grid-community/src/ts/rendering/cellComp.ts
Expand Up @@ -463,10 +463,10 @@ export class CellComp extends Component {
_.addCssClass(element, fullName);
_.removeCssClass(element, animationFullName);
// then once that is applied, we remove the highlight with animation
setTimeout(() => {
window.setTimeout(() => {
_.removeCssClass(element, fullName);
_.addCssClass(element, animationFullName);
setTimeout(() => {
window.setTimeout(() => {
// and then to leave things as we got them, we remove the animation
_.removeCssClass(element, animationFullName);
}, 1000);
Expand Down Expand Up @@ -895,7 +895,7 @@ export class CellComp extends Component {

if (colDef.onCellContextMenu) {
// to make the callback async, do in a timeout
setTimeout(() => (colDef.onCellContextMenu as any)(cellContextMenuEvent), 0);
window.setTimeout(() => (colDef.onCellContextMenu as any)(cellContextMenuEvent), 0);
}
}

Expand Down Expand Up @@ -944,7 +944,7 @@ export class CellComp extends Component {
// check if colDef also wants to handle event
if (typeof colDef.onCellDoubleClicked === 'function') {
// to make the callback async, do in a timeout
setTimeout(() => (colDef.onCellDoubleClicked as any)(cellDoubleClickedEvent), 0);
window.setTimeout(() => (colDef.onCellDoubleClicked as any)(cellDoubleClickedEvent), 0);
}

const editOnDoubleClick = !this.beans.gridOptionsWrapper.isSingleClickEdit()
Expand Down Expand Up @@ -1445,7 +1445,7 @@ export class CellComp extends Component {

if (colDef.onCellClicked) {
// to make callback async, do in a timeout
setTimeout(() => (colDef.onCellClicked as any)(cellClickedEvent), 0);
window.setTimeout(() => (colDef.onCellClicked as any)(cellClickedEvent), 0);
}

const editOnSingleClick = (this.beans.gridOptionsWrapper.isSingleClickEdit() || colDef.singleClickEdit)
Expand Down
Expand Up @@ -62,7 +62,7 @@ export class AnimateShowChangeCellRenderer extends Component implements ICellRen
// is not the most recent and will not try to remove the delta value.
this.refreshCount++;
const refreshCountCopy = this.refreshCount;
setTimeout(() => {
window.setTimeout(() => {
if (refreshCountCopy === this.refreshCount) {
this.hideDeltaValue();
}
Expand Down

0 comments on commit 30d1727

Please sign in to comment.