Ask for globals

44 views
Skip to first unread message

Pedro Nicolás Cuadra Guamán

unread,
Feb 14, 2016, 3:03:02 PM2/14/16
to polym...@googlegroups.com
Hello again Polymer, team. I'm looking for a way to make globals, is to say, variables or functions, because I dont want to make a huge web component that contains theese globals.

Karl Tiedt

unread,
Feb 14, 2016, 3:23:58 PM2/14/16
to Pedro Nicolás Cuadra Guamán, Polymer

It's just JavaScript... No special consideration required if you feel you must use globals.

On Feb 14, 2016 12:03, "Pedro Nicolás Cuadra Guamán" <pedrx...@gmail.com> wrote:
Hello again Polymer, team. I'm looking for a way to make globals, is to say, variables or functions, because I dont want to make a huge web component that contains theese globals.

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/CABUE4gibJBLCk2igb9hcrJ1D2nT4H5iDuRdk9FcFSS1Pc6RE0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Eric Bidelman

unread,
Feb 14, 2016, 3:58:51 PM2/14/16
to Karl Tiedt, Pedro Nicolás Cuadra Guamán, Polymer
Also, web components might not be a good fit for your use case. As Karl said, there's nothing wrong with vanilla JS to define functions / globals.

Pedro Nicolás Cuadra Guamán

unread,
Feb 14, 2016, 4:47:54 PM2/14/16
to polym...@googlegroups.com
Sorry i'm not expert with Polymer, but, How can I manipulate an "on-change" event external to the web component in JS? any link? I would appreciate you so much

Pedro Nicolás Cuadra Guamán

unread,
Feb 14, 2016, 4:48:59 PM2/14/16
to polym...@googlegroups.com
PD: I want to control a <paper-radio-group>

Pedro Nicolás Cuadra Guamán

unread,
Feb 14, 2016, 6:08:47 PM2/14/16
to polym...@googlegroups.com
Don't worry, I solved the problem using jQuery:

$("<paper-radio-group>").on("paper-radio-group-changed",function(){
   //...
})

Greetings from Chile

Eric Bidelman

unread,
Feb 14, 2016, 7:24:18 PM2/14/16
to Pedro Nicolás Cuadra Guamán, polym...@googlegroups.com

Exactly. You can listen to the event using addEventListener and other methods. They're just DOM events :)


Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.

Justin Fagnani

unread,
Feb 16, 2016, 12:40:53 PM2/16/16
to Pedro Nicolás Cuadra Guamán, polymer-dev
On Sun, Feb 14, 2016 at 3:08 PM, Pedro Nicolás Cuadra Guamán <pedrx...@gmail.com> wrote:
Don't worry, I solved the problem using jQuery:

$("<paper-radio-group>").on("paper-radio-group-changed",function(){
   //...
})


You shouldn't need jQuery, with Polymer or just with plain JS. In fact, jQquery is dangerous because it doesn't know about the Shady DOM scoping and will select elements across shadow boundaries.

In a Polymer element, this.$$(s) is an alias for this.root.querySelector(s), so to add an event handler just do:

this.$$('paper-radio-group').addEventListener('paper-radio-group-changed', () => { ... });

This query is scoped to the element both in native shadow DOM and in ShadyDOM.

If you want a document-level handlers, you can just use standard DOM APIs:

document.querySelector('paper-radio-group').addEventListener('paper-radio-group-changed', () => { ... });

Note that under shady DOM that query won't be scoped to just the document's light-dom, but will select the first paper-radio-group, even in a shadow. Same with jQuery. I'd use that pattern with great caution, or better not at all.

Cheers,
  Justin

 
Greetings from Chile

2016-02-14 18:48 GMT-03:00 Pedro Nicolás Cuadra Guamán <pedrx...@gmail.com>:
PD: I want to control a <paper-radio-group>

2016-02-14 18:47 GMT-03:00 Pedro Nicolás Cuadra Guamán <pedrx...@gmail.com>:
Sorry i'm not expert with Polymer, but, How can I manipulate an "on-change" event external to the web component in JS? any link? I would appreciate you so much



Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages