[英]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. 我正在将Polymer 1行为转换为Polymer 3 mixin。
With the Polymer 1 behaviors, I was able to place a host property in the behavior. 使用Polymer 1行为,我可以在该行为中放置一个主机属性。 Is that possible with Polymer 3 Mixins?
Polymer 3 Mixins可以做到吗?
Polymer 1 behavior: 聚合物1的行为:
<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 但是我写了这个
module
来查找元素的宿主
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.