0

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>
dman
  • 10,406
  • 18
  • 102
  • 201

1 Answers1

1

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);
  }
akc42
  • 4,893
  • 5
  • 41
  • 60