简体   繁体   中英

Polymer 3 Mixin - Possible to implement host property in mixin like in Polymer 1 behaviors?

I am converting a Polymer 1 behavior to a Polymer 3 mixin.

With the Polymer 1 behaviors, I was able to place a host property in the behavior. Is that possible with Polymer 3 Mixins?

Polymer 1 behavior:

<script>
  AccountBehavior = {
    properties: {
      tabactivated: Boolean
    },

    observers: ['_refreshActivePosts(tabactivated)'],

    _refreshActivePosts: function(tabactivated) {
      if (tabactivated) {
        this.$.account.refreshAjax();
      }
    }
  }
</script>

Not sure I can remember exactly what the old host property does. But I have this module which I wrote to find the host of an element

export default function domHost(self) {
  let parent = self.parentNode;
  while(parent && parent.nodeType !== 11) {
    parent = parent.parentNode;  //work up the hierarchy
  }

  return parent ? parent.host : self;
}

I use it quite a lot to add event listeners to my hosting element something like this:-

 connectedCallback() {
    super.connectedCallback();
    this.domHost = domHost(this);
    this.domHost.addEventListener('pas-filelocation-request', this._gotRequest);
  }
  disconnectedCallback() {
    super.disconnectedCallback();
    this.domHost.removeEventListener('pas-filelocation-request', this._gotRequest);
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM