mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
add memoize function and use it for makeEnvironment
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { escape, htmlTrim, idGenerator } from "../../src/ts/core/utils";
|
||||
import {
|
||||
escape,
|
||||
htmlTrim,
|
||||
idGenerator,
|
||||
memoize
|
||||
} from "../../src/ts/core/utils";
|
||||
|
||||
describe("escape", () => {
|
||||
test("normal strings", () => {
|
||||
@@ -34,3 +39,23 @@ describe("idGenerator", () => {
|
||||
expect(gen()).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user