refactor: improve setState semantics

This commit is contained in:
Baptiste Grob
2020-07-07 11:55:04 +02:00
parent 15039bd16c
commit e45d28b07a

View File

@@ -59,15 +59,13 @@ export class PureViewCtrl<P = CtrlProps, S = CtrlState> {
return {} as any; return {} as any;
} }
async setState(state: CtrlState) { async setState(state: Partial<S>) {
if (!this.$timeout) { if (!this.$timeout) {
return; return;
} }
this.state = Object.freeze(Object.assign({}, this.state, state));
return new Promise((resolve) => { return new Promise((resolve) => {
this.stateTimeout = this.$timeout(() => { this.stateTimeout = this.$timeout(resolve);
this.state = Object.freeze(Object.assign({}, this.state, state));
resolve();
});
}); });
} }