cleanup, rename setState into updateState

This commit is contained in:
Géry Debongnie
2019-03-19 10:05:46 +01:00
parent 7d10e57cc0
commit 695636e60e
11 changed files with 61 additions and 60 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ export class Clock extends Widget<{}, State> {
}
updateTime() {
this.setState({ currentTime: new Date().toLocaleTimeString() });
this.updateState({ currentTime: new Date().toLocaleTimeString() });
}
startClock() {
@@ -34,6 +34,6 @@ export class Counter extends Widget<Props, State> {
}
increment(delta: number) {
this.setState({ counter: this.state.counter + delta });
this.updateState({ counter: this.state.counter + delta });
}
}
@@ -22,25 +22,25 @@ export class Discuss extends Widget<{}, State> {
resetCounter(ev: MouseEvent) {
if (this.refs.counter instanceof Counter) {
this.refs.counter.setState({ counter: 3 });
this.refs.counter.updateState({ counter: 3 });
}
}
resetCounterAsync(ev: MouseEvent) {
setTimeout(() => {
if (this.refs.counter2 instanceof Counter) {
this.refs.counter2.setState({ counter: 300 });
this.refs.counter2.updateState({ counter: 300 });
}
}, 3000);
}
toggle() {
this.setState({ validcounter: !this.state.validcounter });
this.updateState({ validcounter: !this.state.validcounter });
}
toggleColor() {
const newColor = this.state.color === "red" ? "blue" : "red";
this.setState({ color: newColor });
this.updateState({ color: newColor });
}
addNotif(sticky: boolean) {
+1 -1
View File
@@ -24,7 +24,7 @@ export class Root extends Widget<Store, State> {
}
mounted() {
this.store.on("state_updated", this, this.setState);
this.store.on("state_updated", this, this.updateState);
this.store.on("rpc_status", this, this.toggleLoadingIndicator);
this.store.on("update_action", this, this.applyController);
if (this.store.lastController) {
+2 -2
View File
@@ -28,10 +28,10 @@ export class PureWidget<P, S> extends Widget<P, S> {
}
return false;
}
async setState(nextState: Partial<S>) {
async updateState(nextState: Partial<S>) {
for (let k in nextState) {
if (nextState[k] !== this.state[k]) {
return super.setState(nextState);
return super.updateState(nextState);
}
}
}
+1 -1
View File
@@ -114,7 +114,7 @@
<button t-on-click="resetCounterAsync">Reset counter 2 in 3s</button>
<button t-on-click="toggle">Toggle Clock/counters</button>
<button t-on-click="toggleColor">Toggle Color</button>
<button t-on-click="setState({})">Rerender this widget</button>
<button t-on-click="updateState({})">Rerender this widget</button>
<input t-ref="textinput"/>
<t t-if="state.validcounter">
<t t-widget="Counter" t-ref="counter" t-props="{initialState:4}"/>