[IMP] add browser bindings to standard environment

This could be done by each application, but it does cost only a few
lines of code, and it helps standardizing the Owl ecosystem.

For example, some library (such as o_spreadsheet) needs to mock side
effects, and Odoo also needs to do that, so this prevents duplicated effort.

closes #686
This commit is contained in:
Géry Debongnie
2020-04-17 12:12:02 +02:00
committed by aab-odoo
parent 142b69823f
commit 1707bd240d
7 changed files with 70 additions and 9 deletions
+5 -3
View File
@@ -10,6 +10,8 @@
* - debounce
*/
import { browser } from "./browser";
export function whenReady(fn?: any) {
return new Promise(function(resolve) {
if (document.readyState !== "loading") {
@@ -44,7 +46,7 @@ export function loadJS(url: string): Promise<void> {
}
export async function loadFile(url: string): Promise<string> {
const result = await fetch(url);
const result = await browser.fetch(url);
if (!result.ok) {
throw new Error("Error while fetching xml templates");
}
@@ -83,8 +85,8 @@ export function debounce(func: Function, wait: number, immediate?: boolean): Fun
}
}
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
browser.clearTimeout(timeout);
timeout = browser.setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}