Skip to content

Commit

Permalink
refactor(engine): updating customElement for 0.22.x
Browse files Browse the repository at this point in the history
  • Loading branch information
caridy committed May 31, 2018
1 parent d689da6 commit 0353057
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/lwc-engine/src/framework/wc.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { getComponentDef, registerComponent } from "./def";
import { ComponentConstructor } from "./component";
import { isUndefined } from "./language";
import { createVM, appendVM, renderVM, removeVM } from "./vm";
import { getCustomElementVM } from "./html-element";
import { isUndefined, isObject, isNull } from "./language";
import { createVM, appendVM, renderVM, removeVM, getCustomElementVM } from "./vm";
import assert from "./assert";
import { resolveCircularModuleDependency } from "./utils";

export function customElement(Ctor: ComponentConstructor): Function {
let mustBeRegistered = true;
export function customElement(Ctor: ComponentConstructor, options?: Record<string, boolean>): Function {
Ctor = resolveCircularModuleDependency(Ctor);
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}.`);
}
const normalizedOptions = { fallback: false, mode: 'open', isRoot: true };
if (isObject(options) && !isNull(options)) {
const { mode, fallback } = (options as any);
// TODO: for now, we default to open, but eventually it should default to 'closed'
if (mode === 'closed') { normalizedOptions.mode = mode; }
// fallback defaults to false to favor shadowRoot
if (fallback === true) { normalizedOptions.fallback = true; }
}
return class extends HTMLElement {
constructor() {
super();
const tagName = this.tagName.toLocaleLowerCase();
if (mustBeRegistered) {
mustBeRegistered = false;
registerComponent(tagName, Ctor);
}
createVM(tagName, this);
createVM(tagName, this, Ctor, normalizedOptions);
}
connectedCallback() {
const vm = getCustomElementVM(this);
Expand Down

0 comments on commit 0353057

Please sign in to comment.