Skip to content

Commit

Permalink
fix(setImmediate): replaced by setTimeout(fn, 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Aug 18, 2021
1 parent fe6d8da commit fa82b15
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 40 deletions.
4 changes: 1 addition & 3 deletions src/Common/Core/CompositeClosureHelper/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { setImmediate } from 'paraviewweb/src/Common/Core';

// ----------------------------------------------------------------------------
// capitalize provided string
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -113,7 +111,7 @@ function event(publicAPI, model, eventName, asynchrounous = true) {
}

if (asynchrounous) {
setImmediate(processCallbacks);
setTimeout(processCallbacks, 0);
} else {
processCallbacks();
}
Expand Down
5 changes: 2 additions & 3 deletions src/Common/Core/LookupTableManager/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Monologue from 'monologue.js';

import { setImmediate } from 'paraviewweb/src/Common/Core';
import LookupTable from 'paraviewweb/src/Common/Core/LookupTable';

const TOPIC = {
Expand Down Expand Up @@ -57,9 +56,9 @@ export default class LookupTableManager {
}

updateActiveLookupTable(name) {
setImmediate(() => {
setTimeout(() => {
this.emit(TOPIC.ACTIVE_CHANGE, name);
});
}, 0);
this.activeField = name;
}

Expand Down
4 changes: 0 additions & 4 deletions src/Common/Core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import CompositeClosureHelper from './CompositeClosureHelper';
import LookupTable from './LookupTable';
import LookupTableManager from './LookupTableManager';

export function setImmediate(fn) {
return setTimeout(fn, 0);
}

export default {
CompositeClosureHelper,
LookupTable,
Expand Down
3 changes: 1 addition & 2 deletions src/Component/Native/ToggleControl/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global document */
import { setImmediate } from 'paraviewweb/src/Common/Core';
import style from 'PVWStyle/ComponentNative/ToggleControl.mcss';

const SELECTOR_BUTTON_CLASS = style.jsControlButton;
Expand All @@ -18,7 +17,7 @@ export default class CompositeControlContainer {
this.container.querySelector(
`.${style.jsControlContent}`
).style.display = this.controlVisible ? 'flex' : 'none';
setImmediate(() => this.resize());
setTimeout(() => this.resize(), 0);
}
};
}
Expand Down
11 changes: 5 additions & 6 deletions src/IO/Core/QueryDataModel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import now from 'mout/src/time/now';
import omit from 'mout/object/omit';
import size from 'mout/object/size';

import { setImmediate } from 'paraviewweb/src/Common/Core';
import DataManager from 'paraviewweb/src/IO/Core/DataManager';

// ============================================================================
Expand Down Expand Up @@ -136,9 +135,9 @@ export default class QueryDataModel {

if (hasPending) {
// put the request back in the queue
setImmediate(() => {
setTimeout(() => {
this.requests.push(request);
});
}, 0);
} else if (!hasError) {
// We are good to go
// Broadcast data to the category
Expand Down Expand Up @@ -192,11 +191,11 @@ export default class QueryDataModel {

if (minValue === maxValue && (dataSize === 1 ? minValue === 0 : true)) {
// Handling requests after any re-queue
setImmediate(() => {
setTimeout(() => {
while (this.requests.length) {
processRequest(this.requests.pop());
}
});
}, 0);
}
};

Expand Down Expand Up @@ -260,7 +259,7 @@ export default class QueryDataModel {

this.explorationSubscription = this.onDataChange(() => {
if (this.exploreState.animate && this.exploreState.onDataReady) {
setImmediate((_) => this.nextExploration());
setTimeout((_) => this.nextExploration(), 0);
}
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/InfoViz/Native/HistogramSelector/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import d3 from 'd3';
import style from 'PVWStyle/InfoVizNative/HistogramSelector.mcss';

import { setImmediate } from 'paraviewweb/src/Common/Core';
import CompositeClosureHelper from 'paraviewweb/src/Common/Core/CompositeClosureHelper';
import multiClicker from 'paraviewweb/src/InfoViz/Core/D3MultiClick';
import score from 'paraviewweb/src/InfoViz/Native/HistogramSelector/score';
Expand Down Expand Up @@ -837,7 +836,7 @@ function histogramSelector(publicAPI, model) {
.classed(style.parameterScrollFix, true);
publicAPI.resize();

setImmediate(scoreHelper.updateFieldAnnotations);
setTimeout(scoreHelper.updateFieldAnnotations, 0);
}
};

Expand Down
9 changes: 4 additions & 5 deletions src/InfoViz/Native/ParallelCoordinates/AxesManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { setImmediate } from 'paraviewweb/src/Common/Core';
import { dataToScreen } from 'paraviewweb/src/InfoViz/Native/ParallelCoordinates';
import Axis from 'paraviewweb/src/InfoViz/Native/ParallelCoordinates/Axis';
import SelectionBuilder from 'paraviewweb/src/Common/Misc/SelectionBuilder';
Expand Down Expand Up @@ -258,7 +257,7 @@ export default class AxesManager {
}

triggerSelectionChange(reset = true) {
setImmediate(() => {
setTimeout(() => {
if (reset) {
this.selection = null;
}
Expand All @@ -269,7 +268,7 @@ export default class AxesManager {
listener(selection);
}
});
});
}, 0);
}

onAxisListChange(callback) {
Expand All @@ -282,14 +281,14 @@ export default class AxesManager {
}

triggerAxisListChange() {
setImmediate(() => {
setTimeout(() => {
// Notify listeners
this.axisListChangeListeners.forEach((listener) => {
if (listener) {
listener(this.getAxesPairs());
}
});
});
}, 0);
}

getSelection() {
Expand Down
5 changes: 2 additions & 3 deletions src/React/CollapsibleControls/LightControl/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';

import { setImmediate } from 'paraviewweb/src/Common/Core';
import style from 'PVWStyle/ReactCollapsibleControls/LightControl.mcss';

import CollapsibleWidget from '../../Widgets/CollapsibleWidget';
Expand All @@ -24,11 +23,11 @@ export default class LightControl extends React.Component {
const newState = {};
newState[name] = newVal;
this.setState(newState);
setImmediate(() => {
setTimeout(() => {
this.props.light.setLightProperties({
lightTerms: newState,
});
});
}, 0);
}

onLightPositionChange(event) {
Expand Down
5 changes: 2 additions & 3 deletions src/React/CollapsibleControls/ProbeControl/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';

import { setImmediate } from 'paraviewweb/src/Common/Core';
import NumberSliderWidget from '../../Widgets/NumberSliderWidget';
import CollapsibleWidget from '../../Widgets/CollapsibleWidget';

Expand Down Expand Up @@ -76,7 +75,7 @@ export default class ProbeControl extends React.Component {
showFieldValue: isProbeOpen,
});

setImmediate(() => {
setTimeout(() => {
if (this.props.imageBuilders) {
Object.keys(this.props.imageBuilders).forEach((key) => {
const builder = this.props.imageBuilders[key].builder;
Expand All @@ -88,7 +87,7 @@ export default class ProbeControl extends React.Component {
this.props.imageBuilder.setCrossHairEnable(isProbeOpen);
this.props.imageBuilder.render();
}
});
}, 0);
}

attachImageBuilderListeners(imageBuilder) {
Expand Down
3 changes: 1 addition & 2 deletions src/React/Containers/OverlayWindow/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';

import { setImmediate } from 'paraviewweb/src/Common/Core';
import style from 'PVWStyle/ReactContainers/OverlayWindow.mcss';

/* eslint-disable react/no-unused-prop-types */
Expand Down Expand Up @@ -364,7 +363,7 @@ export default class OverlayWindow extends React.Component {
const actionStruct = this.computeActionRegion(evt);
this.dragHandler = this.mouseMove;
this.setState({ cursor: actionStruct.cursor, dragging: false });
setImmediate(() => this.props.onActive(false, this));
setTimeout(() => this.props.onActive(false, this), 0);
}

render() {
Expand Down
6 changes: 2 additions & 4 deletions src/React/Viewers/Probe3DViewer/example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import 'normalize.css';
import React from 'react';
import ReactDOM from 'react-dom';

import { setImmediate } from 'paraviewweb/src/Common/Core';

import jsonData from 'tonic-arctic-sample-data/data/probe/index.json';

import ImageBuilder from 'paraviewweb/src/Rendering/Image/DataProberImageBuilder';
Expand All @@ -27,6 +25,6 @@ ReactDOM.render(
bodyElement
);

setImmediate(() => {
setTimeout(() => {
dataModel.fetchData();
});
}, 0);
5 changes: 2 additions & 3 deletions src/React/Widgets/TextInputWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';

import { setImmediate } from 'paraviewweb/src/Common/Core';
import style from 'PVWStyle/ReactWidgets/TextInputWidget.mcss';

export default class TextInputWidget extends React.Component {
Expand Down Expand Up @@ -55,10 +54,10 @@ export default class TextInputWidget extends React.Component {
this.setState({ valueRep: this.props.value });
if (this.props.escEndsEdit) {
// needs to happen at next idle so it happens after setState.
setImmediate(() => {
setTimeout(() => {
this.textInput.blur();
if (!this.props.blurEndsEdit) this.endEditing();
});
}, 0);
}
}
}
Expand Down

0 comments on commit fa82b15

Please sign in to comment.