[REF] utils: remove id generator

This commit is contained in:
Géry Debongnie
2019-04-25 16:44:48 +02:00
parent 8f7d06a5bd
commit cf47f8459a
3 changed files with 2 additions and 25 deletions
+2 -7
View File
@@ -1,10 +1,8 @@
import { EventBus } from "./event_bus";
import { Observer } from "./observer";
import { QWeb } from "./qweb";
import { idGenerator } from "./utils";
import { h, patch, VNode } from "./vdom";
let getId = idGenerator();
//------------------------------------------------------------------------------
// Types/helpers
@@ -33,13 +31,10 @@ export interface Meta<T extends Env, Props> {
observer?: Observer;
}
export interface Type<T> extends Function {
new (...args: any[]): T;
}
//------------------------------------------------------------------------------
// Widget
//------------------------------------------------------------------------------
let nextId = 1;
export class Component<
T extends Env,
@@ -92,7 +87,7 @@ export class Component<
// Con: this is not really safe
// Pro: but creating widget (by a template) is always unsafe anyway
this.props = <Props>props || <Props>{};
let id: number = getId();
let id: number = nextId++;
let p: Component<T, any, any> | null = null;
if (parent instanceof Component) {
p = parent;
-8
View File
@@ -27,14 +27,6 @@ export function htmlTrim(s: string): string {
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 function memoize<R, T extends (...args: any[]) => R>(
-10
View File
@@ -1,7 +1,6 @@
import {
escape,
htmlTrim,
idGenerator,
memoize,
debounce,
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", () => {
test("return correct value", () => {
const f = memoize((a, b) => a + b);