Skip to content

Commit

Permalink
resolving issue with the internal registration of the lwc
Browse files Browse the repository at this point in the history
  • Loading branch information
caridy committed Feb 13, 2018
1 parent 54ddada commit 97e06f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/lwc-engine/src/framework/__tests__/wc-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Element } from "../main";
import { customElement } from "../wc";

describe('wc', () => {

it('should create a new constructor from LWCElement', () => {
class MyComponent extends Element {}
const WC = customElement(MyComponent);
expect(typeof WC).toBe('function');
});

});
10 changes: 8 additions & 2 deletions packages/lwc-engine/src/framework/wc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getComponentDef } from "./def";
import { getComponentDef, registerComponent } from "./def";
import { ComponentConstructor } from "./component";
import { keys, isUndefined, ArrayPush } from "./language";
import { invokeComponentAttributeChangedCallback } from "./invoker";
Expand All @@ -10,6 +10,7 @@ import { getPropNameFromAttrName, getAttrNameFromPropName } from "./utils";
export function customElement(Ctor: ComponentConstructor): Function {
const def = getComponentDef(Ctor);
const attrs = keys(def.observedAttrs);
let mustBeRegistered = true;
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isUndefined(Ctor.forceTagName), `The experimental support for web components does not include the support for \`static forceTagName\` to "${Ctor.forceTagName}" declaration in the class definition for ${Ctor}.`);
// adding attributes that cannot be reflected into attributes
Expand All @@ -23,7 +24,12 @@ export function customElement(Ctor: ComponentConstructor): Function {
return class extends HTMLElement {
constructor() {
super();
createVM(this.tagName.toLocaleLowerCase(), this);
const tagName = this.tagName.toLocaleLowerCase();
if (mustBeRegistered) {
mustBeRegistered = false;
registerComponent(tagName, Ctor);
}
createVM(tagName, this);
}
connectedCallback() {
const vm = getCustomElementVM(this);
Expand Down

0 comments on commit 97e06f1

Please sign in to comment.