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;
}
async setState(state: CtrlState) {
async setState(state: Partial<S>) {
if (!this.$timeout) {
return;
}
this.state = Object.freeze(Object.assign({}, this.state, state));
return new Promise((resolve) => {
this.stateTimeout = this.$timeout(() => {
this.state = Object.freeze(Object.assign({}, this.state, state));
resolve();
});
this.stateTimeout = this.$timeout(resolve);
});
}