Skip to content
Snippets Groups Projects
Commit 5467c694 authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: auto-apply tweak

parent 96595fa8
No related branches found
No related tags found
No related merge requests found
...@@ -114,13 +114,20 @@ abstract class TransformContolBase<P, S extends TransformContolBase.ControlState ...@@ -114,13 +114,20 @@ abstract class TransformContolBase<P, S extends TransformContolBase.ControlState
} }
private autoApplyHandle: number | undefined = void 0; private autoApplyHandle: number | undefined = void 0;
private clearAutoApply() {
if (this.autoApplyHandle !== void 0) {
clearTimeout(this.autoApplyHandle);
this.autoApplyHandle = void 0;
}
}
events: StateTransformParameters.Props['events'] = { events: StateTransformParameters.Props['events'] = {
onEnter: this.onEnter, onEnter: this.onEnter,
onChange: (params, isInitial, errors) => { onChange: (params, isInitial, errors) => {
this.clearAutoApply();
this.setState({ params, isInitial, error: errors && errors[0] }, () => { this.setState({ params, isInitial, error: errors && errors[0] }, () => {
if (!isInitial && !this.state.error && this.canAutoApply(params)) { if (!isInitial && !this.state.error && this.canAutoApply(params)) {
if (this.autoApplyHandle) clearTimeout(this.autoApplyHandle); this.clearAutoApply();
this.autoApplyHandle = setTimeout(this.apply, 50) as any as number; this.autoApplyHandle = setTimeout(this.apply, 50) as any as number;
} }
}); });
...@@ -128,10 +135,7 @@ abstract class TransformContolBase<P, S extends TransformContolBase.ControlState ...@@ -128,10 +135,7 @@ abstract class TransformContolBase<P, S extends TransformContolBase.ControlState
} }
apply = async () => { apply = async () => {
if (this.autoApplyHandle !== void 0) { this.clearAutoApply();
clearTimeout(this.autoApplyHandle);
this.autoApplyHandle = void 0;
}
this.setState({ busy: true }); this.setState({ busy: true });
try { try {
await this.applyAction(); await this.applyAction();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment