mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
cleanup, rename setState into updateState
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}"/>
|
||||
|
||||
Reference in New Issue
Block a user