From cf47f8459a6d0ec471f2ca07930b983d95667b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 25 Apr 2019 16:44:48 +0200 Subject: [PATCH] [REF] utils: remove id generator --- src/component.ts | 9 ++------- src/utils.ts | 8 -------- tests/utils.test.ts | 10 ---------- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/src/component.ts b/src/component.ts index aa9366c0..e17ce15e 100644 --- a/src/component.ts +++ b/src/component.ts @@ -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 { observer?: Observer; } -export interface Type 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 || {}; - let id: number = getId(); + let id: number = nextId++; let p: Component | null = null; if (parent instanceof Component) { p = parent; diff --git a/src/utils.ts b/src/utils.ts index a07064db..5f3795b4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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>( diff --git a/tests/utils.test.ts b/tests/utils.test.ts index b15ba167..4afa573d 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -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);