I had the feeling that with this approach, one ends with having really reusable web parts.
What I did not understand well is if programmer is encouraged or not to use web component's public API to handle their behaviour and work with them, and, if it's so, how to access webcomponents API.
For example, with Polymer you may define your custom component like this:
Once defined, you may include it in a regular HTML page as custom tag
but how you can have access to component's API ? In my example, component API consists in only one trivial function, doSomething() . Since created() function is automatically invoked, I tried to register it in a custom array added to window object.
This solution works - despite the fact I should use an associative array (with component's ID as key) and take care to make customVariable instance a singleton : if in main web page containing my custom component I use window.customVariables to get a "reference" to my components,
I can programmatically invoke its public functions.
Anyway the fact it works doesn't mean that it's a good approach. On the opposite, I believe mine is a sloppy approach, and I'd love to have your suggestion about which techniques are best suited to address similar problems.
I hadn't heard of Polymer. It looks cool. I don't know the answer to your question. Got to comment that if you can write that and are using words like "associative array", you are a programmer. Maybe an early one, but still a programmer.
Disclaimer: I'm no Polymer expert - this is what I found after poking around for a bit.
You get the component instance's interface by getting a hold of the custom component's DOM element.
Polymer 1.0 fires the 'WebComponentsReady' event when all the components have been constructed. At that point in time a selector can be used to grab the custom element from the DOM - then you can use the component's properties and methods.
I never imagined to accomplish that with querySelector - I thought that querySelector returned only the DOM element, not its methods too.
But that's my problem. I can't help thing the java way and I continue to forget that in Java script you can easily decorate any object you have with any method or property you like - I thinks that's the way Polymer works under the hood..
Thanks. I think that your example is enlightening.