SauloSilva/jcep

View on GitHub
src/aggregation.js

Summary

Maintainability
A
0 mins
Test Coverage
let aggregation = (baseClass, ...mixins) => {
  let base = class _Combined extends baseClass {
    constructor(...args) {
      super(...args);

      mixins.forEach((mixin) => {
        mixin.prototype.initializer.call(this);
      });
    }
  };

  let copyProps = (target, source) => {
    Object.getOwnPropertyNames(source)
      .concat(Object.getOwnPropertySymbols(source))
      .forEach((prop) => {
        if (prop.match(/^(?:constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/)) {
          return;
        };

        Object.defineProperty(target, prop, Object.getOwnPropertyDescriptor(source, prop));
      });
  };

  mixins.forEach((mixin) => {
    copyProps(base.prototype, mixin.prototype);
    copyProps(base, mixin);
  });

  return base;
};

module.exports = aggregation;