move internal stuff in _, add unique id for each widget

This commit is contained in:
Géry Debongnie
2019-01-25 14:27:16 +01:00
parent c1dd38bf03
commit 9fc7cf0c68
5 changed files with 60 additions and 21 deletions
+10 -1
View File
@@ -1,4 +1,4 @@
import { escape, htmlTrim } from "../src/ts/core/utils";
import { escape, htmlTrim, idGenerator } from "../src/ts/core/utils";
describe("escape", () => {
test("normal strings", () => {
@@ -25,3 +25,12 @@ describe("htmlTrim", () => {
expect(htmlTrim("")).toBe("");
});
});
describe("idGenerator", () => {
test("basic use", () => {
let gen = idGenerator();
expect(gen()).toBe(1);
expect(gen()).toBe(2);
expect(gen()).toBe(3);
});
});
+4 -2
View File
@@ -1,4 +1,5 @@
import { Widget, WEnv } from "../src/ts/core/widget";
import { idGenerator } from "../src/ts/core/utils";
import { QWeb } from "../src/ts/core/qweb_vdom";
interface Type<T> extends Function {
@@ -9,8 +10,9 @@ type TestEnv = WEnv;
type TestWidget = Widget<TestEnv>;
function makeWidget(W: Type<TestWidget>): TestWidget {
const env = {
qweb: new QWeb()
const env: WEnv = {
qweb: new QWeb(),
getID: idGenerator()
};
const w = new W(env);
return w;