mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
improve root widget code
This commit is contained in:
@@ -25,27 +25,29 @@ export class Root extends Widget<Store, State> {
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.store.on("state_updated", this, this.updateState);
|
this.store.on("state_updated", this, this.updateState);
|
||||||
|
this.store.on("rpc_status", this, this.toggleLoadingIndicator);
|
||||||
// loading indicator
|
|
||||||
this.store.on("rpc_status", this, status => {
|
|
||||||
const method = status === "loading" ? "remove" : "add";
|
|
||||||
(<any>this.refs.loading_indicator).classList[method]("d-none");
|
|
||||||
});
|
|
||||||
|
|
||||||
// adding reactiveness to mobile/non mobile
|
|
||||||
window.addEventListener("resize", <any>debounce(() => {
|
|
||||||
const isMobile = window.innerWidth <= 768;
|
|
||||||
if (isMobile !== this.env.isMobile) {
|
|
||||||
this.env.isMobile = isMobile;
|
|
||||||
this.render();
|
|
||||||
}
|
|
||||||
}, 50));
|
|
||||||
|
|
||||||
// actions
|
|
||||||
this.store.on("update_action", this, this.applyAction);
|
this.store.on("update_action", this, this.applyAction);
|
||||||
if (this.store.lastAction) {
|
if (this.store.lastAction) {
|
||||||
this.applyAction(this.store.lastAction);
|
this.applyAction(this.store.lastAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adding reactiveness to mobile/non mobile
|
||||||
|
window.addEventListener("resize", <any>(
|
||||||
|
debounce(this.applyMobileInterface.bind(this), 50)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
applyMobileInterface() {
|
||||||
|
const isMobile = window.innerWidth <= 768;
|
||||||
|
if (isMobile !== this.env.isMobile) {
|
||||||
|
this.env.isMobile = isMobile;
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleLoadingIndicator(status: "loading" | "notloading") {
|
||||||
|
const method = status === "loading" ? "remove" : "add";
|
||||||
|
(<any>this.refs.loading_indicator).classList[method]("d-none");
|
||||||
}
|
}
|
||||||
|
|
||||||
async applyAction(action: Action) {
|
async applyAction(action: Action) {
|
||||||
|
|||||||
Reference in New Issue
Block a user