mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REM] utils: remove findInTree and htmlTrim
They were not used and are not in the scope of this project.
This commit is contained in:
@@ -13,20 +13,6 @@ export function escape(str: string | number | undefined): string {
|
||||
.replace(/`/g, "`");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove trailing and leading spaces
|
||||
*/
|
||||
export function htmlTrim(s: string): string {
|
||||
let result = s.replace(/(^\s+|\s+$)/g, "");
|
||||
if (s[0] === " ") {
|
||||
result = " " + result;
|
||||
}
|
||||
if (result !== " " && s[s.length - 1] === " ") {
|
||||
result = result + " ";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export type HashFn = (args: any[]) => string;
|
||||
|
||||
export function memoize<R, T extends (...args: any[]) => R>(
|
||||
@@ -79,32 +65,6 @@ export function debounce(
|
||||
};
|
||||
}
|
||||
|
||||
interface Tree<T> {
|
||||
children: T[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a node in a tree.
|
||||
*
|
||||
* This will traverse the tree (depth first) and return the first child that
|
||||
* matches the predicate, if any
|
||||
*/
|
||||
export function findInTree<T extends Tree<T>>(
|
||||
tree: T,
|
||||
predicate: (t: T) => boolean
|
||||
): T | null {
|
||||
if (predicate(tree)) {
|
||||
return tree;
|
||||
}
|
||||
for (let child of tree.children) {
|
||||
let match = findInTree(child, predicate);
|
||||
if (match) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function patch(C: any, patchName: string, patch: any) {
|
||||
const proto = C.prototype;
|
||||
if (!proto.__patches) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import {
|
||||
escape,
|
||||
htmlTrim,
|
||||
memoize,
|
||||
debounce,
|
||||
findInTree,
|
||||
patch,
|
||||
unpatch
|
||||
} from "../src/utils";
|
||||
@@ -20,20 +18,6 @@ describe("escape", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("htmlTrim", () => {
|
||||
test("basic use", () => {
|
||||
expect(htmlTrim("abc")).toBe("abc");
|
||||
expect(htmlTrim(" abc")).toBe(" abc");
|
||||
expect(htmlTrim("abc ")).toBe("abc ");
|
||||
expect(htmlTrim(" abc ")).toBe(" abc ");
|
||||
expect(htmlTrim("abc\n ")).toBe("abc ");
|
||||
expect(htmlTrim("\n ")).toBe(" ");
|
||||
expect(htmlTrim(" \n ")).toBe(" ");
|
||||
expect(htmlTrim(" ")).toBe(" ");
|
||||
expect(htmlTrim("")).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("memoize", () => {
|
||||
test("return correct value", () => {
|
||||
const f = memoize((a, b) => a + b);
|
||||
@@ -71,19 +55,6 @@ describe("debounce", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("findInTree", () => {
|
||||
test("can find stuff in tree", () => {
|
||||
let tree = {
|
||||
id: 1,
|
||||
children: [{ id: 2, children: [] }, { id: 3, key: "hello", children: [] }]
|
||||
};
|
||||
const match1 = findInTree(tree, t => t.id === 3);
|
||||
expect((<any>match1).key).toBe("hello");
|
||||
const match2 = findInTree(tree, t => t.id === 4);
|
||||
expect(match2).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("patch/unpatch", () => {
|
||||
test("can monkey patch a class", () => {
|
||||
class Test {
|
||||
|
||||
Reference in New Issue
Block a user