Skip to content

Commit

Permalink
fixed ot component scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyOGo committed Apr 30, 2018
1 parent a1cfb44 commit dc98ba8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
22 changes: 10 additions & 12 deletions src/js/abstract/base-component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nanomorph from 'nanomorph';
import nanomorph from './component-morph';
import getAttribute from '../get-attribute';
import toProp from '../to-prop';
import { publish, subscribe } from '../pubsub';
Expand Down Expand Up @@ -398,17 +398,6 @@ export default class BaseComponent extends HTMLElement {
this.render();
}

/**
* Monkey patch `childNodes` API to re-rendering.
*/
get childNodes() {
if (this._isMorphing || !this._hasTemplate || !this._hasRendered) {
return super.childNodes;
}

return [];
}

/**
* Monkey patch `appendChild` API to re-rendering.
*
Expand All @@ -425,6 +414,15 @@ export default class BaseComponent extends HTMLElement {
this.render();
}

/**
* Only morph children of current custom element, not any other custom element.
*
* @returns {boolean}
*/
skipChildren() {
return !this._isMorphing;
}

// @TODO: atm no data can be shared by enabling context, though this could be necessary
/**
* Provides an opt-in contextual scope for hierarchy-agnostic child components.
Expand Down
6 changes: 5 additions & 1 deletion src/js/abstract/component-morph.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ function walk(newNode, oldNode) {
}

morph(newNode, oldNode);
updateChildren(newNode, oldNode);

if (!oldNode.skipChildren && !oldNode.skipChildren()) {
updateChildren(newNode, oldNode);
}

return oldNode;
}

Expand Down

0 comments on commit dc98ba8

Please sign in to comment.