In Polymer 0.5 the advice on globals was as outlined in this question/answer:
However in Polymer 1.0 this doesn't seem to work. Change notifications are not automatically generated on the underlying model, they are generated on the <dom-module>
instead which means that change notifications will be generated on only one of the <app-globals>
.
What is the recommended way of implementing this pattern in Polymer 1.0?
I have tried to improve on Alexei Volkov's answer, but I wanted to define the global variables separately. Instead of the getters/setters I used the
observer
property and saved the key together with the instances.The usage is:
whereas the
key
property defines the name of the global variable.So for example you can use:
Definition of the
<app-data>
dom module:Fully working demo is here: http://jsbin.com/femaceyusa/1/edit?html,output
Using ootwch's solution, I ran into a race condition situation with lazy-loaded components.
As posted, lazy-loaded components are not initialized with the value from the shared data.
In case anyone else runs into the same problem, I think I fixed it by adding a ready callback like this:
Hope this saves someone some pain.