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

Changes to make compatible with noPatch version of ShadyDOM [3.x] #5452

Merged
merged 39 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e752636
Adds basic legacy support for ShadyDOM.unPatch (WIP)
Oct 26, 2018
079ac3b
remove cruft
Oct 26, 2018
b211436
rename test file.
Nov 1, 2018
1bce4f0
Add back event tests.
Nov 19, 2018
0f022df
Manual merge from `perf-opt-disable-upgrade` branch.
Nov 20, 2018
21c644c
Merge branch 'behaviors-no-mixin-disable-upgrade' into shady-nopatch
Nov 20, 2018
05a7e1c
Merge branch 'master' into shady-nopatch
Dec 7, 2018
c3bd4d6
Revert "Manual merge from `perf-opt-disable-upgrade` branch."
Dec 7, 2018
e3b3baa
Update to match 2.x branch
Dec 7, 2018
acbe649
Fix typos
Dec 7, 2018
b8f3b79
More shady compatible wrapping
Dec 8, 2018
42b13d0
Changes based on review.
Dec 8, 2018
8954c25
Changes based on review.
Dec 8, 2018
bade986
Temporarily disable type genration
Dec 10, 2018
a2e597c
Make `noPatch` safe with older versions of ShadyDOM
Dec 11, 2018
e4b56e4
Closure typing fixes
dfreedm Dec 17, 2018
e73285b
compromise with typescript and closure
dfreedm Dec 17, 2018
4e4d6fe
Make sure `_valueToNodeAttribute` uses wrap
Dec 20, 2018
d8aac3b
Fix typo
Dec 20, 2018
8e50602
[wrap] Fix doc comment.
Dec 20, 2018
491c2a7
Ensure dispatchEvent is wrapped
Jan 30, 2019
fc7858c
Make initial distribution synchronous when `legacyOptimizations` is set
Jan 30, 2019
d4857ec
Adds `syncInitialRender` setting
Jan 31, 2019
a50aee3
Merge branch 'master' into shady-nopatch
Feb 4, 2019
0a91b15
Update webcomponents vesrion.
Feb 4, 2019
c93fc48
Update package-lock
Feb 4, 2019
391715f
Fix test in IE/Edge
Feb 5, 2019
a272506
Fix test warning in Edge/IE
Feb 5, 2019
9be29bd
Merge branch 'master' into shady-nopatch
kevinpschaaf Feb 5, 2019
c398c83
Merge branch 'master' into shady-nopatch
kevinpschaaf Feb 5, 2019
e3c6b25
Backport closure compiler fixes from internal
dfreedm Feb 6, 2019
42735d1
Ensure argument types match.
kevinpschaaf Feb 6, 2019
4a24ba3
Refactor symbols to make gen-typescript-declarations happy
kevinpschaaf Feb 6, 2019
ae899c5
Remove semicolon after class definition (lint).
kevinpschaaf Feb 6, 2019
fb24656
use JSCompiler_renameProperty bare
dfreedm Feb 6, 2019
4321da0
address feedback
dfreedm Feb 6, 2019
aba0f90
Add `@fileoverview`, put `@suppress` after it
dfreedm Feb 6, 2019
9328274
Merge pull request #5480 from Polymer/closure-compiler-fixes
kevinpschaaf Feb 6, 2019
073d25f
Use webcomponents 2.2.7 for initialSync tests
dfreedm Feb 6, 2019
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
3 changes: 2 additions & 1 deletion lib/elements/dom-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PropertyEffects } from '../mixins/property-effects.js';
import { OptionalMutableData } from '../mixins/mutable-data.js';
import { GestureEventListeners } from '../mixins/gesture-event-listeners.js';
import { strictTemplatePolicy } from '../utils/settings.js';
import { wrap } from '../utils/wrap.js';

/**
* @constructor
Expand Down Expand Up @@ -87,7 +88,7 @@ export class DomBind extends domBindBase {
}

__insertChildren() {
this.parentNode.insertBefore(this.root, this);
wrap(wrap(this).parentNode).insertBefore(this.root, this);
}

__removeChildren() {
Expand Down
28 changes: 15 additions & 13 deletions lib/elements/dom-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Debouncer } from '../utils/debounce.js';
import { enqueueDebouncer, flush } from '../utils/flush.js';
import { microTask } from '../utils/async.js';
import { root } from '../utils/path.js';
import { wrap } from '../utils/wrap.js';

/**
* The `<dom-if>` element will stamp a light-dom `<template>` child when
Expand Down Expand Up @@ -120,9 +121,9 @@ export class DomIf extends PolymerElement {
*/
disconnectedCallback() {
super.disconnectedCallback();
if (!this.parentNode ||
(this.parentNode.nodeType == Node.DOCUMENT_FRAGMENT_NODE &&
!this.parentNode.host)) {
const parent = wrap(this).parentNode;
if (!parent || (parent.nodeType == Node.DOCUMENT_FRAGMENT_NODE &&
!wrap(parent).host)) {
this.__teardownInstance();
}
}
Expand Down Expand Up @@ -174,15 +175,15 @@ export class DomIf extends PolymerElement {
}

__ensureInstance() {
let parentNode = this.parentNode;
let parentNode = wrap(this).parentNode;
// Guard against element being detached while render was queued
if (parentNode) {
if (!this.__ctor) {
let template = /** @type {HTMLTemplateElement} */(this.querySelector('template'));
let template = /** @type {HTMLTemplateElement} */(wrap(this).querySelector('template'));
if (!template) {
// Wait until childList changes and template should be there by then
let observer = new MutationObserver(() => {
if (this.querySelector('template')) {
if (wrap(this).querySelector('template')) {
observer.disconnect();
this.__render();
} else {
Expand Down Expand Up @@ -219,16 +220,16 @@ export class DomIf extends PolymerElement {
}
if (!this.__instance) {
this.__instance = new this.__ctor();
parentNode.insertBefore(this.__instance.root, this);
wrap(parentNode).insertBefore(this.__instance.root, this);
} else {
this.__syncHostProperties();
let c$ = this.__instance.children;
if (c$ && c$.length) {
// Detect case where dom-if was re-attached in new position
let lastChild = this.previousSibling;
let lastChild = wrap(this).previousSibling;
if (lastChild !== c$[c$.length-1]) {
for (let i=0, n; (i<c$.length) && (n=c$[i]); i++) {
parentNode.insertBefore(n, this);
wrap(parentNode).insertBefore(n, this);
}
}
}
Expand All @@ -253,10 +254,11 @@ export class DomIf extends PolymerElement {
let c$ = this.__instance.children;
if (c$ && c$.length) {
// use first child parent, for case when dom-if may have been detached
let parent = c$[0].parentNode;
// Instance children may be disconnected from parents when dom-if
// detaches if a tree was innerHTML'ed
if (parent) {
let parent = wrap(c$[0]).parentNode;
// Instance children may be disconnected from parents when dom-if
// detaches if a tree was innerHTML'ed
if (parent) {
parent = wrap(parent);
for (let i=0, n; (i<c$.length) && (n=c$[i]); i++) {
parent.removeChild(n);
}
Expand Down
11 changes: 7 additions & 4 deletions lib/elements/dom-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { enqueueDebouncer, flush } from '../utils/flush.js';
import { OptionalMutableData } from '../mixins/mutable-data.js';
import { matches, translate } from '../utils/path.js';
import { timeOut, microTask } from '../utils/async.js';
import { wrap } from '../utils/wrap.js';

/**
* @constructor
Expand Down Expand Up @@ -323,9 +324,9 @@ export class DomRepeat extends domRepeatBase {
// only perform attachment if the element was previously detached.
if (this.__isDetached) {
this.__isDetached = false;
let parent = this.parentNode;
let wrappedParent = wrap(wrap(this).parentNode);
for (let i=0; i<this.__instances.length; i++) {
this.__attachInstance(i, parent);
this.__attachInstance(i, wrappedParent);
}
}
}
Expand Down Expand Up @@ -583,15 +584,17 @@ export class DomRepeat extends domRepeatBase {

__detachInstance(idx) {
let inst = this.__instances[idx];
const wrappedRoot = wrap(inst.root);
for (let i=0; i<inst.children.length; i++) {
let el = inst.children[i];
inst.root.appendChild(el);
wrappedRoot.appendChild(el);
}
return inst;
}

__attachInstance(idx, parent) {
let inst = this.__instances[idx];
// Note, this is pre-wrapped as an optimization
parent.insertBefore(inst.root, this);
}

Expand Down Expand Up @@ -625,7 +628,7 @@ export class DomRepeat extends domRepeatBase {
}
let beforeRow = this.__instances[instIdx + 1];
let beforeNode = beforeRow ? beforeRow.children[0] : this;
this.parentNode.insertBefore(inst.root, beforeNode);
wrap(wrap(this).parentNode).insertBefore(inst.root, beforeNode);
this.__instances[instIdx] = inst;
return inst;
}
Expand Down
22 changes: 13 additions & 9 deletions lib/legacy/legacy-element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
import '@webcomponents/shadycss/entrypoints/apply-shim.js';

import { ElementMixin } from '../mixins/element-mixin.js';
import { GestureEventListeners } from '../mixins/gesture-event-listeners.js';
import { DirMixin } from '../mixins/dir-mixin.js';
Expand All @@ -20,6 +19,7 @@ import { setTouchAction } from '../utils/gestures.js';
import { Debouncer } from '../utils/debounce.js';
import { timeOut, microTask } from '../utils/async.js';
import { get } from '../utils/path.js';
import { wrap } from '../utils/wrap.js';

let styleInterface = window.ShadyCSS;

Expand Down Expand Up @@ -419,7 +419,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
});
event.detail = detail;
let node = options.node || this;
node.dispatchEvent(event);
wrap(node).dispatchEvent(event);
return event;
}

Expand Down Expand Up @@ -506,6 +506,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
* @override
*/
$$(slctr) {
// Note, no need to `wrap` this because root is always patched
return this.root.querySelector(slctr);
}

Expand All @@ -516,7 +517,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
* @this {Element}
*/
get domHost() {
let root = this.getRootNode();
let root = wrap(this).getRootNode();
return (root instanceof DocumentFragment) ? /** @type {ShadowRoot} */ (root).host : root;
}

Expand All @@ -528,7 +529,9 @@ export const LegacyElementMixin = dedupingMixin((base) => {
* @override
*/
distributeContent() {
if (window.ShadyDOM && this.shadowRoot) {
const thisEl = /** @type {Element} */ (this);
const domApi = /** @type {DomApi} */(dom(thisEl));
if (window.ShadyDOM && domApi.shadowRoot) {
ShadyDOM.flush();
}
}
Expand Down Expand Up @@ -638,6 +641,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
* @override
*/
getContentChildNodes(slctr) {
// Note, no need to `wrap` this because root is always
let content = this.root.querySelector(slctr || 'slot');
return content ?
/** @type {PolymerDomApi} */ (dom(content)).getDistributedNodes() :
Expand Down Expand Up @@ -678,8 +682,8 @@ export const LegacyElementMixin = dedupingMixin((base) => {
*/
isLightDescendant(node) {
const thisNode = /** @type {Node} */ (this);
return thisNode !== node && thisNode.contains(node) &&
thisNode.getRootNode() === node.getRootNode();
return thisNode !== node && wrap(thisNode).contains(node) &&
wrap(thisNode).getRootNode() === wrap(node).getRootNode();
}

/**
Expand All @@ -690,7 +694,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
* @override
*/
isLocalDescendant(node) {
return this.root === node.getRootNode();
return this.root === wrap(node).getRootNode();
}

/**
Expand Down Expand Up @@ -883,10 +887,10 @@ export const LegacyElementMixin = dedupingMixin((base) => {
bool = !node.hasAttribute(name);
}
if (bool) {
node.setAttribute(name, '');
wrap(node).setAttribute(name, '');
return true;
} else {
node.removeAttribute(name);
wrap(node).removeAttribute(name);
return false;
}
}
Expand Down
Loading