Polymer 3 Mixin - 可以像 Polymer 1 行为一样在 mixin 中实现主机 属性 吗?
Polymer 3 Mixin - Possible to implement host property in mixin like in Polymer 1 behaviors?
我正在将 Polymer 1 行为转换为 Polymer 3 混入。
通过 Polymer 1 行为,我能够在行为中放置宿主 属性。 Polymer 3 Mixins 有可能吗?
聚合物 1 行为:
<script>
AccountBehavior = {
properties: {
tabactivated: Boolean
},
observers: ['_refreshActivePosts(tabactivated)'],
_refreshActivePosts: function(tabactivated) {
if (tabactivated) {
this.$.account.refreshAjax();
}
}
}
</script>
不确定我是否能准确记得旧主机 属性 是做什么的。但是我有这个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;
}
我经常使用它来向我的托管元素添加事件侦听器
像这样:-
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);
}
我正在将 Polymer 1 行为转换为 Polymer 3 混入。
通过 Polymer 1 行为,我能够在行为中放置宿主 属性。 Polymer 3 Mixins 有可能吗?
聚合物 1 行为:
<script>
AccountBehavior = {
properties: {
tabactivated: Boolean
},
observers: ['_refreshActivePosts(tabactivated)'],
_refreshActivePosts: function(tabactivated) {
if (tabactivated) {
this.$.account.refreshAjax();
}
}
}
</script>
不确定我是否能准确记得旧主机 属性 是做什么的。但是我有这个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;
}
我经常使用它来向我的托管元素添加事件侦听器 像这样:-
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);
}