I am creating a custom module for Polymer. I need to create a global variable that can be accessed when defining a template. Something like:
<template is="dom-if" if="[[_check(myGlobalVar.foo)]]">
The global variable should also be directly accessible from inside the module (see _anotherFunction) . The JS file looks like:
Polymer({
is: 'my-module',
_check(f) {
return f == 'foobar'
},
_anotherFunction() {
console.log(myGlobalVar)
}
})
In addition, myGlobalVar should be accessible from other modules in other files. What's the best way to create it?
You can achieve that in two ways.
Have a component that can hold all the global variables and gives the same instance of its data where ever it is used. You can find the better explanation using link along with working sample
If you have lot of data that needs to be accessible globally then the best option would be using store with polymer-redux.