move mobile reactiveness code from main to root

This commit is contained in:
Géry Debongnie
2019-02-05 16:04:02 +01:00
parent 311141a9e3
commit abbf077977
2 changed files with 12 additions and 12 deletions
+1 -11
View File
@@ -1,9 +1,8 @@
///<amd-module name="main" />
import { debounce } from "./core/utils";
import { makeEnvironment } from "./env";
import { Root } from "./widgets/root";
import { BaseMenuItem, processMenuItems } from "./misc/menu_helpers";
import { Root } from "./widgets/root";
//------------------------------------------------------------------------------
// Application bootstrapping
@@ -21,13 +20,4 @@ document.addEventListener("DOMContentLoaded", async function() {
const rootWidget = new Root(env, { menuInfo });
await rootWidget.mount(document.body);
(<any>window).odoo.rootWidget = rootWidget;
// adding reactiveness to mobile/non mobile
window.addEventListener("resize", <any>debounce(() => {
const isMobile = window.innerWidth <= 768;
if (isMobile !== env.isMobile) {
env.isMobile = isMobile;
rootWidget.render();
}
}, 50));
});
+11 -1
View File
@@ -1,6 +1,7 @@
import { INotification } from "../core/notifications";
import { Widget } from "./widget";
import { Env } from "../env";
import { debounce } from "../core/utils";
import { Env } from "./widget";
import { MenuInfo, MenuItem, getAppAndAction } from "../misc/menu_helpers";
import { ActionStack } from "../services/action_manager";
import { ActionContainer } from "./action_container";
@@ -60,6 +61,15 @@ export class Root extends Widget<Props, State> {
);
this.env.router.on("query_changed", this, this.updateAction);
this.updateAction(this.env.router.getQuery());
// 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));
}
private updateAction(query: Query) {