I have been having some scope issues when developing a Polymer app. Essentially I am attempting to use custom elements as classes containing pertinent logic.
Say I have a listener that is listening for a click event on a custom-elem element, and I want to access a function in another element, in this case the elements parent, parent:
<polymer-element name="custom-elem">
<template>
</template>
<script>
Polymer({
attached: function(){
this.addEventListener('mousedown', function(e) {
if (e.which === 1){
this.parentNode.parentNode.testFunc(e);
//or this.parentNode.querySelector.... etc
}
else if (e.which === 3){
}
}.bind(this));
}
</script>
</polymer-element>
I find I have to traverse the DOM to find the element I am looking for, or create a reference in a newly created element. I realize I could create an object in an external script that contains logic above, but that seems to invalidate the purpose of defining custom elements / web components.
Is there anyway to easily access members of Polymer registered elements without navigating the DOM and without creating external scripts?