Skip to content

Commit

Permalink
fix(engine): exposing host (#705)
Browse files Browse the repository at this point in the history
* fix(engine): exposing host
* fix(engine): shadow root
* wip(engine): linting and type errors
* fix(engine): cleaning up shadow root detection
* fix(engine): removing restrictions test
* fix(engine): fixing element from point methods
* fix(engine): disabling some attribute integration test for now
* fix(engine): linting
* fix(engine): upgrade ie11 driver
* fix(engine): compat test fix
* fix(engine): applying elementFromPoint on document
* fix(engine): linting
* fix(engine): reverting unnecessary changes
* fix(engine): removing skip in test
* fix(engine): polyfill readmes
  • Loading branch information
davidturissini authored Oct 9, 2018
1 parent 2ed6513 commit 047a5b8
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@ import { getHostShadowRoot } from '../../framework/html-element';

describe('root', () => {
describe('integration', () => {
it.skip('should support this.template.host', () => {});
it('should support template.host', () => {
const html = compileTemplate(`
<template></template>
`);
class Parent extends LightningElement {
getHost() {
return this.template.host;
}
render() {
return html;
}
}
Parent.publicMethods = ['getHost'];
const elm = createElement('x-parent', { is: Parent });
expect(elm.getHost()).toBe(elm);
expect(elm.shadowRoot.host).toBe(elm);
});

it('should support this.template.mode', () => {
class MyComponent extends LightningElement {}
Expand Down
4 changes: 2 additions & 2 deletions packages/lwc-engine/src/faux-shadow/custom-element.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineProperties } from "../shared/language";
import { attachShadow, getShadowRoot } from "./shadow-root";
import { attachShadow, getShadowRoot, SyntheticShadowRoot } from "./shadow-root";
import { addCustomElementEventListener, removeCustomElementEventListener } from "./events";

function addEventListenerPatchedValue(this: EventTarget, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) {
Expand All @@ -10,7 +10,7 @@ function removeEventListenerPatchedValue(this: EventTarget, type: string, listen
removeCustomElementEventListener(this as HTMLElement, type, listener, options);
}

function attachShadowGetter(this: HTMLElement, options: ShadowRootInit): ShadowRoot {
function attachShadowGetter(this: HTMLElement, options: ShadowRootInit): SyntheticShadowRoot {
return attachShadow(this, options);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/lwc-engine/src/faux-shadow/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ const {
createElementNS,
createTextNode,
createComment,
} = document;
elementsFromPoint,
} = Document.prototype;

export {
createElement,
createElementNS,
createTextNode,
createComment,
DocumentPrototypeActiveElement,
elementsFromPoint,
};
8 changes: 4 additions & 4 deletions packages/lwc-engine/src/faux-shadow/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "./node";
import { ArraySlice, ArraySplice, ArrayIndexOf, create, ArrayPush, isUndefined, isFunction, getOwnPropertyDescriptor, defineProperties, toString, forEach, defineProperty, isFalse } from "../shared/language";
import { compareDocumentPosition, DOCUMENT_POSITION_CONTAINED_BY, getNodeOwnerKey, getNodeKey } from "./node";
import { getHost } from "./shadow-root";
import { getHost, SyntheticShadowRoot } from "./shadow-root";

interface WrappedListener extends EventListener {
placement: EventListenerContext;
Expand Down Expand Up @@ -178,7 +178,7 @@ function getEventMap(elm: HTMLElement): ListenerMap {

const shadowRootEventListenerMap: WeakMap<EventListener, WrappedListener> = new WeakMap();

function getWrappedShadowRootListener(sr: ShadowRoot, listener: EventListener): WrappedListener {
function getWrappedShadowRootListener(sr: SyntheticShadowRoot, listener: EventListener): WrappedListener {
if (!isFunction(listener)) {
throw new TypeError(); // avoiding problems with non-valid listeners
}
Expand Down Expand Up @@ -357,7 +357,7 @@ export function removeCustomElementEventListener(elm: HTMLElement, type: string,
detachDOMListener(elm, type, wrappedListener);
}

export function addShadowRootEventListener(sr: ShadowRoot, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) {
export function addShadowRootEventListener(sr: SyntheticShadowRoot, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) {
if (process.env.NODE_ENV !== 'production') {
assert.invariant(isFunction(listener), `Invalid second argument for this.template.addEventListener() in ${toString(sr)} for event "${type}". Expected an EventListener but received ${listener}.`);
// TODO: issue #420
Expand All @@ -374,7 +374,7 @@ export function addShadowRootEventListener(sr: ShadowRoot, type: string, listene
attachDOMListener(elm, type, wrappedListener);
}

export function removeShadowRootEventListener(sr: ShadowRoot, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) {
export function removeShadowRootEventListener(sr: SyntheticShadowRoot, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions) {
const elm = getHost(sr);
const wrappedListener = getWrappedShadowRootListener(sr, listener);
detachDOMListener(elm, type, wrappedListener);
Expand Down
Loading

0 comments on commit 047a5b8

Please sign in to comment.