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

Use setTimeout instead of setImmediate #1482

Merged
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-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