Patterns: How to support global variables #318
Comments
Here's a jsbin for the first approach: And here's my attempt at the second: Neither approach seems to work in stable. |
@eee-c might be interested in this |
Bindings within <style> elements don't work out of the box with the shimmed Binding to style seems unnecessary to demonstrate passing data around like On Tue, Mar 11, 2014 at 10:43 AM, Rob Dodson notifications@github.comwrote:
|
I've also seen |
Platform.mixin(a, b); mixes the properties in object b into object a. On Tue, Mar 11, 2014 at 11:30 AM, Eric Bidelman notifications@github.comwrote:
|
Doc global variables approach (for #318)
This landed. #334 is improving on the existing docs. |
Is there a way to add the tag just once at a higher level, rather than including it in each template? |
We have http://www.polymer-project.org/docs/polymer/polymer.html#static that talks about static vars. Expanding on this:
MonoState Pattern for this. When defining Polymer element, define a closure that closes over the variables in question, and then provide accessors on the object's prototype or copy them over to individual instances in the constructor.
Then use the element as you would any other, and data-bind it to a property that you can use to access it through Polymer's normal model-driven views templating:
(The Shadow DOM polyfill currently has issues with data-binding in
<style>
tags, but it should work under native Shadow DOM.)A slight tweak of this approach will let you configure the value of the globals externally:
In the main page (not in any component):
Usage within components would be the same - we're just changing how the values are defined, not how they're used.
The text was updated successfully, but these errors were encountered: