如何在 Polmyer 2.x 中获取 mixin 中所有属性的列表?

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

我有一个 mixin 和一个使用它的 class,但是在 mixin(或 class 本身)中,我似乎无法获得所有属性的列表。 this.configundefined,而 this.constructor.config 只给我当前 class 中的属性列表(而不是混合本身中的属性)。

有关更详细的示例,请参见下文。

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

在控制台中,我只看到变量something。如何获得所有属性的列表(例如 mixInVariablesomething)?

constructor,使用 super.constructor.config.properties 访问继承的属性。

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

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

来自 get properties(),使用 super.config.properties

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

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

codepen