mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] utils: remove id generator
This commit is contained in:
+2
-7
@@ -1,10 +1,8 @@
|
|||||||
import { EventBus } from "./event_bus";
|
import { EventBus } from "./event_bus";
|
||||||
import { Observer } from "./observer";
|
import { Observer } from "./observer";
|
||||||
import { QWeb } from "./qweb";
|
import { QWeb } from "./qweb";
|
||||||
import { idGenerator } from "./utils";
|
|
||||||
import { h, patch, VNode } from "./vdom";
|
import { h, patch, VNode } from "./vdom";
|
||||||
|
|
||||||
let getId = idGenerator();
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Types/helpers
|
// Types/helpers
|
||||||
@@ -33,13 +31,10 @@ export interface Meta<T extends Env, Props> {
|
|||||||
observer?: Observer;
|
observer?: Observer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Type<T> extends Function {
|
|
||||||
new (...args: any[]): T;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Widget
|
// Widget
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
let nextId = 1;
|
||||||
|
|
||||||
export class Component<
|
export class Component<
|
||||||
T extends Env,
|
T extends Env,
|
||||||
@@ -92,7 +87,7 @@ export class Component<
|
|||||||
// Con: this is not really safe
|
// Con: this is not really safe
|
||||||
// Pro: but creating widget (by a template) is always unsafe anyway
|
// Pro: but creating widget (by a template) is always unsafe anyway
|
||||||
this.props = <Props>props || <Props>{};
|
this.props = <Props>props || <Props>{};
|
||||||
let id: number = getId();
|
let id: number = nextId++;
|
||||||
let p: Component<T, any, any> | null = null;
|
let p: Component<T, any, any> | null = null;
|
||||||
if (parent instanceof Component) {
|
if (parent instanceof Component) {
|
||||||
p = parent;
|
p = parent;
|
||||||
|
|||||||
@@ -27,14 +27,6 @@ export function htmlTrim(s: string): string {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a function that will generate unique id numbers
|
|
||||||
*/
|
|
||||||
export function idGenerator(): () => number {
|
|
||||||
let nextID = 1;
|
|
||||||
return () => nextID++;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type HashFn = (args: any[]) => string;
|
export type HashFn = (args: any[]) => string;
|
||||||
|
|
||||||
export function memoize<R, T extends (...args: any[]) => R>(
|
export function memoize<R, T extends (...args: any[]) => R>(
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
escape,
|
escape,
|
||||||
htmlTrim,
|
htmlTrim,
|
||||||
idGenerator,
|
|
||||||
memoize,
|
memoize,
|
||||||
debounce,
|
debounce,
|
||||||
findInTree,
|
findInTree,
|
||||||
@@ -35,15 +34,6 @@ describe("htmlTrim", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("idGenerator", () => {
|
|
||||||
test("basic use", () => {
|
|
||||||
let gen = idGenerator();
|
|
||||||
expect(gen()).toBe(1);
|
|
||||||
expect(gen()).toBe(2);
|
|
||||||
expect(gen()).toBe(3);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("memoize", () => {
|
describe("memoize", () => {
|
||||||
test("return correct value", () => {
|
test("return correct value", () => {
|
||||||
const f = memoize((a, b) => a + b);
|
const f = memoize((a, b) => a + b);
|
||||||
|
|||||||
Reference in New Issue
Block a user