diff --git a/src/qweb_core.ts b/src/qweb_core.ts index 93fe9565..3ef37cf7 100644 --- a/src/qweb_core.ts +++ b/src/qweb_core.ts @@ -1,5 +1,4 @@ import { VNode, h } from "./vdom"; -import { parseXML } from "./utils"; /** * Owl QWeb Engine @@ -110,6 +109,16 @@ export const UTILS = { } }; +function parseXML(xml: string): Document { + const parser = new DOMParser(); + const doc = parser.parseFromString(xml, "text/xml"); + if (doc.getElementsByTagName("parsererror").length) { + throw new Error("Invalid XML in template"); + } + return doc; +} + + //------------------------------------------------------------------------------ // Compilation Context //------------------------------------------------------------------------------ diff --git a/src/utils.ts b/src/utils.ts index 2a44994a..44c7c9ae 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -4,14 +4,12 @@ * We have here a small collection of utility functions: * * - escape - * - memoize * - debounce * - patch * - unpatch * - loadTemplates * - loadJS * - whenReady - * - parseXML */ export function escape(str: string | number | undefined): string { @@ -29,26 +27,6 @@ export function escape(str: string | number | undefined): string { .replace(/`/g, "`"); } -export type HashFn = (args: any[]) => string; - -export function memoize R>( - f: T, - hash?: HashFn -): T { - if (!hash) { - hash = args => args.map(a => String(a)).join(","); - } - let cache: { [key: string]: R } = {}; - function memoizedFunction(...args: any[]) { - let hashValue = hash!(args); - if (!(hashValue in cache)) { - cache[hashValue] = f(...args); - } - return cache[hashValue]; - } - return memoizedFunction as T; -} - /** * Returns a function, that, as long as it continues to be invoked, will not * be triggered. The function will be called after it stops being called for @@ -173,11 +151,3 @@ export function whenReady(fn) { } } -export function parseXML(xml: string): Document { - const parser = new DOMParser(); - const doc = parser.parseFromString(xml, "text/xml"); - if (doc.getElementsByTagName("parsererror").length) { - throw new Error("Invalid XML in template"); - } - return doc; -} diff --git a/tests/utils.test.ts b/tests/utils.test.ts index 294e094b..9515d6c4 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -1,6 +1,5 @@ import { escape, - memoize, debounce, patch, unpatch @@ -18,26 +17,6 @@ describe("escape", () => { }); }); -describe("memoize", () => { - test("return correct value", () => { - const f = memoize((a, b) => a + b); - expect(f(1, 3)).toBe(4); - }); - - test("does not recompute if not needed", () => { - let nCalls = 0; - function origFunction(a: number, b: number): number { - nCalls++; - return a + b; - } - const memoized = memoize(origFunction); - - expect(memoized(1, 3)).toBe(4); - expect(memoized(1, 3)).toBe(4); - expect(nCalls).toBe(1); - }); -}); - describe("debounce", () => { test("works as expected", () => { jest.useFakeTimers();