improve root widget code

This commit is contained in:
Géry Debongnie
2019-03-06 14:28:41 +01:00
parent 9dffcf4cf6
commit 7d317a3764
+15 -13
View File
@@ -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("update_action", this, this.applyAction);
this.store.on("rpc_status", this, status => { if (this.store.lastAction) {
const method = status === "loading" ? "remove" : "add"; this.applyAction(this.store.lastAction);
(<any>this.refs.loading_indicator).classList[method]("d-none"); }
});
// adding reactiveness to mobile/non mobile // adding reactiveness to mobile/non mobile
window.addEventListener("resize", <any>debounce(() => { window.addEventListener("resize", <any>(
debounce(this.applyMobileInterface.bind(this), 50)
));
}
applyMobileInterface() {
const isMobile = window.innerWidth <= 768; const isMobile = window.innerWidth <= 768;
if (isMobile !== this.env.isMobile) { if (isMobile !== this.env.isMobile) {
this.env.isMobile = isMobile; this.env.isMobile = isMobile;
this.render(); this.render();
} }
}, 50));
// actions
this.store.on("update_action", this, this.applyAction);
if (this.store.lastAction) {
this.applyAction(this.store.lastAction);
} }
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) {