0

Polymer 3 and iron-meta. How do I access meta from the <iron-meta></iron-meta> instance? I could do document.createElement in my mixin, but it's cleaner with just one <iron-meta></iron-meta> element to work off of.

Mixin:

let rawApiConstantsMixin = (base) => {
  class foo extends base {
    constructor() {
      super();
    }

    ready() {
      super.ready(); 
      this.FORM_HOST = meta.byKey('FORM_HOST');
    }
  }
  return foo;
};

export const ApiConstantsMixin = dedupingMixin(rawApiConstantsMixin);

class MyView2 extends ApiConstantsMixin(PolymerElement) {
  static get template() {
    return html`
      <style include="shared-styles">
        :host {
          display: block;

          padding: 10px;
        }
      </style>

      <iron-meta></iron-meta>
      <div class="card">
        <div class="circle">2</div>
        <h1>View Two</h1>
        <p>Ea duis bonorum nec, falli paulo aliquid ei eum.</p>
        <p>Id nam odio natum malorum, tibique copiosae expetenda mel ea.Detracto suavitate repudiandae no eum. Id adhuc minim soluta nam.Id nam odio natum malorum, tibique copiosae expetenda mel ea.</p>
      </div>
    `;
  }
}

window.customElements.define('my-view2', MyView2);
dman
  • 10,406
  • 18
  • 102
  • 201

2 Answers2

2

Actually, I ended up not using iron-meta. Since Polymer 3 uses ES6 modules, I just made my own module with the api constants and injected it into the components that need it.

dman
  • 10,406
  • 18
  • 102
  • 201
  • Maybe you want to use redux which would have done way more than that for you. – Pascal L. Aug 27 '18 at 14:26
  • 1
    That was done with https://github.com/Polymer/pwa-starter-kit. But I prefer a minimum code base. If can accomplish the same end result with just a ES6 module, I prefer that overall. – dman Aug 27 '18 at 15:33
  • 1
    Redux can be implemented in 12 lines of code https://www.dalejefferson.com/redux-reimplemented-in-12-lines-of-code/ – Pascal L. Aug 27 '18 at 17:43
  • It's not about the 12 lines of code you see, it's about the lines of code that you don't see. A es6 module is just one line of code `export {}` – dman Aug 27 '18 at 18:24
1

Have you tried to access

window["meta"]

and checked whats in there? maybe you can access is by

window["meta"]["FORM_HOST"]
Pascal L.
  • 1,261
  • 9
  • 21