winjs-polymer-samples icon indicating copy to clipboard operation
winjs-polymer-samples copied to clipboard

What is the recommended way to define statics with polymer for polymer-element class?

Open dglazkov opened this issue 11 years ago • 2 comments

(https://github.com/banguero/winjs-polymer-samples/blob/master/elements/winjs-pivot-item.html). Looking for something different than (http://www.polymer-project.org/docs/polymer/polymer.html#static) where if the definition is <polymer-element name="winjs-pivot-item" constructor="PivotItem" attributes="header">, I would like to set PivotItem.isDeclarativeControlContainer to a function after PivotItem is defined.

dglazkov avatar May 29 '14 18:05 dglazkov

@sjmiles, @sorvell, @ebidel, @robdodson might have a good answer.

dglazkov avatar May 29 '14 18:05 dglazkov

The concept of record is that we add a feature to look for a statics object on the prototype and mix it into the constructor. Something like this:

Polymer({
  statics: {
    staticFunction: function() {}
  }
});

We haven't done this yet, because it bumps into the issue of globals. In other words, you cannot access the constructor (and therefore your statics) without having a reference somewhere. The constructor attribute creates such a reference, but it's in the global context.

Additional musings: it's possible to conceive of polymer-elements as modularized out-of-the-box: you access the module via document.createElement. This idea has not achieved great traction, IMO mostly because of ... perceptual blockage (i.e. people can't wrap their heads around it).

sjmiles avatar May 29 '14 20:05 sjmiles