From 90f30c6c7262c95eede97441ffb5d1f1670b4637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Sat, 26 Jan 2019 20:33:23 +0100 Subject: [PATCH] make sure env is propagated to child widgets --- web/static/src/ts/core/Widget.ts | 2 +- web/static/tests/core/widget.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/web/static/src/ts/core/Widget.ts b/web/static/src/ts/core/Widget.ts index e8d958f3..d65da5ca 100644 --- a/web/static/src/ts/core/Widget.ts +++ b/web/static/src/ts/core/Widget.ts @@ -49,7 +49,7 @@ export class Widget { if (parent instanceof Widget) { p = parent; parent.__widget__.children.push(this); - this.env = Object.create(parent.env); + this.env = parent.env; } else { this.env = parent; } diff --git a/web/static/tests/core/widget.test.ts b/web/static/tests/core/widget.test.ts index bf27be08..89898257 100644 --- a/web/static/tests/core/widget.test.ts +++ b/web/static/tests/core/widget.test.ts @@ -97,6 +97,11 @@ describe("basic widget properties", () => { await widget.mount(fixture); expect(renderCalls).toBe(1); }); + + test("keep a reference to env", async () => { + const widget = new Widget(env); + expect(widget.env).toBe(env); + }); }); describe("lifecycle hooks", () => { @@ -324,4 +329,11 @@ describe("composition", () => { (widget.__widget__.children[0].__widget__.vnode).elm ); }); + + test("parent env is propagated to child widgets", async () => { + const widget = new WidgetA(env); + await widget.mount(fixture); + + expect(widget.__widget__.children[0].env).toBe(env); + }); });