Skip to content

Commit

Permalink
Use setTimeout instead of setImmediate (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
edi9999 authored Oct 18, 2019
1 parent ff3de9b commit 95263d1
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions playground/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class GeoPosition extends Component {
onChange(name) {
return event => {
this.setState({ [name]: parseFloat(event.target.value) });
setImmediate(() => this.props.onChange(this.state));
setTimeout(() => this.props.onChange(this.state), 0);
};
}

Expand Down Expand Up @@ -231,7 +231,7 @@ class Selector extends Component {
return event => {
event.preventDefault();
this.setState({ current: label });
setImmediate(() => this.props.onSelected(samples[label]));
setTimeout(() => this.props.onSelected(samples[label]), 0);
};
};

Expand Down Expand Up @@ -372,10 +372,10 @@ class App extends Component {

onThemeSelected = (theme, { stylesheet, editor }) => {
this.setState({ theme, editor: editor ? editor : "default" });
setImmediate(() => {
setTimeout(() => {
// Side effect!
document.getElementById("theme").setAttribute("href", stylesheet);
});
}, 0);
};

setLiveSettings = ({ formData }) => this.setState({ liveSettings: formData });
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ export function setState(instance, state, callback) {
instance.setState(state, callback);
} else {
instance.setState(state);
setImmediate(callback);
setTimeout(callback, 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/ArrayField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ describe("ArrayField", () => {
},
});

return new Promise(setImmediate).then(() =>
return new Promise(resolve => setTimeout(resolve, 0)).then(() =>
expect(comp.state.formData).eql([
"data:text/plain;name=file1.txt;base64,x=",
"data:text/plain;name=file2.txt;base64,x=",
Expand Down
4 changes: 2 additions & 2 deletions test/StringField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ describe("StringField", () => {
},
});

return new Promise(setImmediate).then(() =>
return new Promise(resolve => setTimeout(resolve, 0)).then(() =>
expect(comp.state.formData).eql(
"data:text/plain;name=file1.txt;base64,x="
)
Expand Down Expand Up @@ -1640,7 +1640,7 @@ describe("StringField", () => {
},
});

return new Promise(setImmediate).then(() =>
return new Promise(resolve => setTimeout(resolve, 0)).then(() =>
expect(comp.state.formData).eql(
"data:text/plain;name=" + uriEncodedValue + ";base64,x="
)
Expand Down
2 changes: 1 addition & 1 deletion test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ describe("utils", () => {
});
});

it.only("should 'resolve' and stub out a schema which contains an `additionalProperties` with a type and definition", () => {
it("should 'resolve' and stub out a schema which contains an `additionalProperties` with a type and definition", () => {
const schema = {
type: "string",
additionalProperties: {
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
new MonacoWebpackPlugin({
languages: ['json']
}),
new MiniCssExtractPlugin({filename: "styles.css", allChunks: true}),
new MiniCssExtractPlugin({ filename: "styles.css", allChunks: true }),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production"),
Expand Down

0 comments on commit 95263d1

Please sign in to comment.