dman
dman

Reputation: 11064

Access iron-meta instance from a Mixin

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);

Upvotes: 0

Views: 63

Answers (2)

dman
dman

Reputation: 11064

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.

Upvotes: 2

Pascal L.
Pascal L.

Reputation: 1259

Have you tried to access

window["meta"]

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

window["meta"]["FORM_HOST"]

Upvotes: 1

Related Questions