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

Coexistence with Polymer 2 components? #48

Closed
vlaraort opened this issue May 10, 2018 · 6 comments
Closed

Coexistence with Polymer 2 components? #48

vlaraort opened this issue May 10, 2018 · 6 comments

Comments

@vlaraort
Copy link

Hi!

There is a way to use polymer 2 components inside a LitElement?

Before yesterday, using the importHref function from polymer 3, I used to be able to load html webcomponents, and load them inside the render() with a tag, but now, with this commit,
https://github.com/Polymer/polymer/commit/fd416a212ed725eef26d3b29bb624ed66669ad76
I am not able anymore to do that.

I have a scenario where I can't migrate polymer 2 components, but I have to use them, so I wonder if its possible to use polymer 2 components (html files) inside a litElement

@TimvdLippe
Copy link
Contributor

You definitely can, as Polymer 2/3 elements and LitElement are all based on webcomponents. For example, this JSBin (http://jsbin.com/pokuwururi/edit?html,output) works in Firefox 60 and Chrome using both a Polymer 2 element as well as the LitElement example. (network could be a bit slow, just because it does a lot of network requests)

However, you are then responsible for doing the integration yourself, meaning you have to take care of the HTML imports and ES modules orchestration. Therefore, we advise you to use Polymer 3 and LitElement together, as they are both based on the same loading mechanism ES modules.

@LarsDenBakker
Copy link
Contributor

@TimvdLippe That's an interesting snippet, thanks for posting that!

The only issue with this I can think of here is duplicate element definitions. For instance both Polymer 2 and 3 will try to register dom-if, dom-repeat etc. right?

@TimvdLippe
Copy link
Contributor

TimvdLippe commented May 10, 2018 via email

@vlaraort
Copy link
Author

vlaraort commented May 11, 2018

Yes, @TimvdLippe is right, but I still have a problem. This snippet works great but is still a html file, previously in a JS file, I could do this:

    import {LitElement, html} from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module';
    import { importHref } from '@polymer/polymer/lib/utils/import-href';

importHref( 'https://polygit.org/polymer+:2.x/paper-checkbox+polymerelements+:master/components/paper-checkbox/paper-checkbox.html', null, null, true);
    class MyElement extends LitElement {

      static get properties() { return { mood: String }}

      _render({mood}) {
        return html`<style> .mood { color: green; } </style>
          Web Components are <span class="mood">${mood}</span>!
          <paper-checkbox></paper-checkbox>`;
      }
    }

    customElements.define('my-element', MyElement);

But now this function is removed, is there a clean solution? or should I replicate the previous importHref polymer function?

@TimvdLippe
Copy link
Contributor

TimvdLippe commented May 11, 2018 via email

@vlaraort
Copy link
Author

ok, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants