import { IncrementalDOM } from '../api/vdom';

const { patch } = IncrementalDOM;
const symbolShadowRoot = '____shadow_root';

export default function (opts) {
  const internalRenderer = opts.render;
  return function (elem) {
    if (!internalRenderer) {
      return;
    }

    let shadowRoot;

    if (!elem[symbolShadowRoot]) {
      if (elem.attachShadow) {
        shadowRoot = elem.attachShadow({ mode: 'open' });
      } else {
        shadowRoot = elem.createShadowRoot();
      }
      elem[symbolShadowRoot] = shadowRoot;
    }

    patch(elem[symbolShadowRoot], internalRenderer, elem);
  };
}

import { IncrementalDOM } from '../api/vdom';

const { patch } = IncrementalDOM;
const symbolShadowRoot = '____shadow_root';

export default function (opts) {
  const internalRenderer = opts.render;
  return function (elem) {
    if (!internalRenderer) {
      return;
    }

    if (!elem[symbolShadowRoot]) {
      let shadowRoot;
      if (elem.attachShadow) {
        shadowRoot = elem.attachShadow({ mode: 'open' });
      } else if (elem.createShadowRoot) {
        shadowRoot = elem.createShadowRoot();
      } else {
        shadowRoot = elem.shadowRoot = elem;
      }
      elem[symbolShadowRoot] = shadowRoot;
    }

    patch(elem[symbolShadowRoot], internalRenderer, elem);
  };
}

Use all forms of shadow root creation. Fallback to the element being it's own shadowRoot.
Use all forms of shadow root creation. Fallback to the element being it's own shadowRoot.
