How to extend multiple elements with Polymer

前端 未结 1 1140
猫巷女王i
猫巷女王i 2020-12-18 03:24

I know there is this question on multiple inheritance/composition. However, it seems like this question is more about how to reuse functionality from multiple existing eleme

相关标签:
1条回答
  • 2020-12-18 04:05

    If you need to have just a single import that has support for being applied to multiple elements, your element could include multiple element definitions which may or may not take advantage of Polymer.mixin in order to share functionality between your decorating elements.

    So pascal-decorator.html could contain Polymer element definitions for <pascal-span> and <pascal-button>, both of which mixin logic from some object defined within pascal-decorator.html. You can then do <button is="pascal-button"> and <button is="pascal-span"> whilst the logic for doing so remains inside the same import.

    The alternative (if you strictly want to do this all in one custom element, which imo, makes this less clean) is to do something like checking against the type of element being extended, which could either be done in the manner you linked to or by checking as part of your element registration process.

    In general, I personally prefer to figure out what logic I may need to share between elements that could be decorated, isolate that functionality into an element and then just import them into dedicated elements that have knowledge about the tag (e.g <addy-button>, <addy-video> etc).

    0 讨论(0)
提交回复
热议问题