• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Google's Polymer and Webcomponents

 
Bartender
Posts: 1316
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These days I had a look at Google's Polymer, and, quite surprisingly for a non web programmer like me, I found it very promising. I liked very much the key idea behind web-components, i.e. define an html fragment (to be imported in other pages) together with its style and javascript parts.
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.

Can you help me, guys ?
 
author & internet detective
Posts: 40801
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Claude Moore
Bartender
Posts: 1316
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,
Thanks for your reply. I'm glad that you found Polymer interesting...for me, it deserves at least a bit of attention.

Jeanne Boyarsky wrote: 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.


Not sure I understood this... Actually, I am a programmer - that is my job - but more server side oriented than a web GUI fan /expert one...
 
Jeanne Boyarsky
author & internet detective
Posts: 40801
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Claude Moore wrote:Not sure I understood this... Actually, I am a programmer - that is my job - but more server side oriented than a web GUI fan /expert one...


Oh! I misread " non web programmer like me" as "non programmer".
 
Claude Moore
Bartender
Posts: 1316
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, no problem... For a while I was afraid that, having read some of my posts, you found them so simple that you thought that only a newbie may have written them..
 
Bartender
Posts: 2968
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Claude Moore
Bartender
Posts: 1316
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's an excellent answer !

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.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad I could be of help.

For me it took Douglas Crockford's JavaScript: The Good Parts to break away from the class-based OO mindset and deal with JavaScript on its own terms - rather than trying to treat it like some other language that I was already comfortable with. Since writing the book he has become even more of a minimalist: Douglas Crockford: The Better Parts - JSConfUY 2014. The fact that ECMAScript 6 (and TypeScript) officially adds classes isn't necessarily a good thing as it doesn't encourage established class-based OO practitioners to move out of their comfort zone and embrace the JavaScript Way.

Dealing with browser's DOM is an entirely separate topic - DOM enlightenment covers some of the basics - though for reference style documentation the Mozilla Developer Network (DOM, JavaScript) is hard to beat.

For the sake of practicing JavaScript outside of the browser environment you may want to have a look at Node.js even if it is just for the convenience of quickly cobbling together a web server to put the the whole "--allow-file-access-from-files" annoyance behind you.

Eric Elliot's Programming JavaScript Applications: Robust Web Architecture with Node, HTML5, and Modern JS Libraries" gives a quick, compact tour of one example of full stack JavaScript.

Basically it takes a bit of work to shake up ye'olde Java mindset.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic