Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(engine): closes #515 by removing lazy init #517

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/lwc-engine/src/faux-shadow/__tests__/slot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { LightningElement, getHostShadowRoot } from "../../framework/html-element";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one still exhibit the circular issue, but changing the order fixes it for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to talk about this. If the import order mater then we still have a circular dependency issue.

Copy link
Contributor

@ravijayaramappa ravijayaramappa Jul 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion: We should use a tool(for example: https://github.com/pahen/madge) to generate a dependency graph of the modules and remove any cyclic dependencies.

import { createElement } from "../../framework/upgrade";
import { compileTemplate } from 'test-utils';
import { LightningElement, getHostShadowRoot } from "../../framework/html-element";

interface LightningSlotElement extends HTMLSlotElement {
assignedElements(options?: object): Element[];
}

describe.skip('slotchange event', () => {
describe('declarative binding', () {
describe('declarative binding', () => {
// Initialized before each test
let element;

Expand Down Expand Up @@ -39,7 +39,7 @@ describe.skip('slotchange event', () => {
});
});

describe('programmatic binding', () {
describe('programmatic binding', () => {
// Initialized before each test
let element;

Expand Down
107 changes: 50 additions & 57 deletions packages/lwc-engine/src/framework/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ function isElementComponent(Ctor: any, protoSet?: any[]): boolean {
}

function createComponentDef(Ctor: ComponentConstructor): ComponentDef {
if (globalInitialization) {
// Note: this routine is just to solve the circular dependencies mess introduced by rollup.
globalInitialization();
}
if (process.env.NODE_ENV !== 'production') {
assert.isTrue(isElementComponent(Ctor), `${Ctor} is not a valid component, or does not extends LightningElement from "lwc". You probably forgot to add the extend clause on the class declaration.`);

Expand Down Expand Up @@ -401,58 +397,55 @@ const globalElmDescriptors: PropertyDescriptorMap = create(null, {
[PatchedFlag]: {}
});

let globalInitialization: any = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the method to just run the code directly during evaluation instead of lazily.

// Note: this routine is just to solve the circular dependencies mess introduced by rollup.
forEach.call(ElementPrototypeAriaPropertyNames, (propName: string) => {
// Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
// in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure.
const descriptor = getPropertyDescriptor(HTMLElement.prototype, propName);
if (!isUndefined(descriptor)) {
const attrName = getAttrNameFromPropName(propName);
HTML_PROPS[propName] = {
config: 3,
type: 'any',
attr: attrName,
};
const globalElmDescriptor = globalElmDescriptors[propName] = {
get: createGetter(propName),
set: createSetter(propName),
enumerable: true,
configurable: true,
};
defineProperty(globalElmProto, propName, globalElmDescriptor);
GLOBAL_PROPS_DESCRIPTORS[propName] = descriptor;
}
});
forEach.call(defaultDefHTMLPropertyNames, (propName) => {
// Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
// in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into
// this category, so, better to be sure.
const descriptor = getPropertyDescriptor(HTMLElement.prototype, propName);
if (!isUndefined(descriptor)) {
const attrName = getAttrNameFromPropName(propName);
HTML_PROPS[propName] = {
config: 3,
type: 'any',
attr: attrName,
};
const globalElmDescriptor = globalElmDescriptors[propName] = {
get: createGetter(propName),
set: createSetter(propName),
enumerable: true,
configurable: true,
};
defineProperty(globalElmProto, propName, globalElmDescriptor);
GLOBAL_PROPS_DESCRIPTORS[propName] = descriptor;
}
});
defineProperties(BaseElement.prototype, createBaseElementStandardPropertyDescriptors(GLOBAL_PROPS_DESCRIPTORS));

if (process.env.NODE_ENV !== 'production') {
patchLightningElementPrototypeWithRestrictions(BaseElement.prototype);
forEach.call(ElementPrototypeAriaPropertyNames, (propName: string) => {
// Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
// in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure.
const descriptor = getPropertyDescriptor(HTMLElement.prototype, propName);
if (!isUndefined(descriptor)) {
const attrName = getAttrNameFromPropName(propName);
HTML_PROPS[propName] = {
config: 3,
type: 'any',
attr: attrName,
};
const globalElmDescriptor = globalElmDescriptors[propName] = {
get: createGetter(propName),
set: createSetter(propName),
enumerable: true,
configurable: true,
};
defineProperty(globalElmProto, propName, globalElmDescriptor);
GLOBAL_PROPS_DESCRIPTORS[propName] = descriptor;
}
});
forEach.call(defaultDefHTMLPropertyNames, (propName) => {
// Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
// in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into
// this category, so, better to be sure.
const descriptor = getPropertyDescriptor(HTMLElement.prototype, propName);
if (!isUndefined(descriptor)) {
const attrName = getAttrNameFromPropName(propName);
HTML_PROPS[propName] = {
config: 3,
type: 'any',
attr: attrName,
};
const globalElmDescriptor = globalElmDescriptors[propName] = {
get: createGetter(propName),
set: createSetter(propName),
enumerable: true,
configurable: true,
};
defineProperty(globalElmProto, propName, globalElmDescriptor);
GLOBAL_PROPS_DESCRIPTORS[propName] = descriptor;
}
});

defineProperties(BaseElement.prototype, createBaseElementStandardPropertyDescriptors(GLOBAL_PROPS_DESCRIPTORS));

if (process.env.NODE_ENV !== 'production') {
patchLightningElementPrototypeWithRestrictions(BaseElement.prototype);
}

freeze(BaseElement);
seal(BaseElement.prototype);
globalInitialization = void(0);
};
freeze(BaseElement);
seal(BaseElement.prototype);