diff --git a/src/store.ts b/src/store.ts index 21f84fd5..3a93ee18 100644 --- a/src/store.ts +++ b/src/store.ts @@ -170,8 +170,6 @@ interface StoreOptions { deep?: boolean; } -let nextID = 1; - export function connect( Comp: Constructor>, mapStoreToProps, @@ -292,7 +290,7 @@ export function connect( // this is necessary for Owl to be able to properly deduce templates. // Otherwise, all connected components would have the same name, and then // each component after the first will necessarily have the same template. - let name = `ConnectedComponent${nextID++}`; + let name = `Connected${Comp.name}`; Object.defineProperty(Result, "name", { value: name }); return Result; } diff --git a/tests/store.test.ts b/tests/store.test.ts index 592cd9fe..e6a5af88 100644 --- a/tests/store.test.ts +++ b/tests/store.test.ts @@ -1157,4 +1157,21 @@ describe("connecting a component to store", () => { expect(fixture.innerHTML).toBe("
b
"); expect(steps).toEqual(["willpatch", "patched"]); }); + + test("connected component has its own name", () => { + function mapStoreToProps() { } + + class Named extends Component { }; + const namedConnected = connect(Named, mapStoreToProps); + expect(namedConnected.name).toMatch('ConnectedNamed'); + + class ParentNamed extends Component{}; + class ChildNamed extends ParentNamed{}; + const childConnected = connect(ChildNamed, mapStoreToProps) + expect(childConnected.name).toMatch('ConnectedChildNamed') + + const Anonymous = class extends Component{ }; + const anonymousConnected = connect(Anonymous, mapStoreToProps); + expect(anonymousConnected.name).toMatch(/^Connectedclass_\d+/); + }); });