How can I get a list of all properties in a mixin in Polmyer 2.x?

458 views Asked by At

I have a mixin and a class that uses it, but within the mixin (or the class itself), I can't seem to get a list of all properties. this.config is undefined, and this.constructor.config only gives me the list of properties in the current class (not those in the mixin itself).

See below for a more detailed example.

const myMixin = subclass => class extends subclass {

    static get config() {
        return {
            properties: {
                mixInVariable: {
                    type: String,
                }
            }   
        }
    }   

    constructor() {
        super();
        console.log(this.constructor.config.properties);
    }

}

class ContainerGrid extends myMixin(Polymer.Element) {

    static get is() { return 'container-grid' }

    static get config() {
        // properties, observers meta data
        return {
            properties: {
                something: {
                    type: String
                }
            }
        };
    }

}

customElements.define(ContainerGrid.is, ContainerGrid);

In the console, I only see the variable something. How can I get a list of all properties (e.g. mixInVariable and something)?

1

There are 1 answers

4
tony19 On BEST ANSWER

From the constructor, use super.constructor.config.properties to access the inherited properties.

class XFoo extends MyMixin(Polymer.Element) {
  ...

  constructor() {
    super();
    console.log('constructor(): ', super.constructor.config.properties);
  }
}

From get properties(), use super.config.properties.

class XFoo extends MyMixin(Polymer.Element) {
  ...

  static get properties() {
    console.log('get properties(): ', super.config.properties);
  }
}

codepen