Coder Social home page Coder Social logo

aggregation's Issues

Symbol props not supported

I am using the nodejs event emitter as a mixin and the in the latest version of nodejs 12.16 they haved added a Symbol property which breaks aggregation.

nodejs/node#31788

if I add add a console.log(prop) to the forEach loop the output is below.
You can see it throws an error when encountering a Symbol which is does have a match method because it is not a string.

I have no idea if these this new Symbol must be mixed in order for the Emitter class to work correctly but if so I have no idea of how to the do that properly.

constructor
_events
_eventsCount
_maxListeners
setMaxListeners
getMaxListeners
emit
addListener
on
prependListener
once
prependOnceListener
removeListener
off
removeAllListeners
listeners
rawListeners
listenerCount
eventNames
Symbol(kCapture)
/mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:1
TypeError: prop.match is not a function
    at /mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:50:18
    at Array.forEach (<anonymous>)
    at copyProps (/mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:48:8)
    at /mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:58:5
    at Array.forEach (<anonymous>)
    at aggregation (/mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:57:10)
    at Object.<anonymous> (/mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/src/sync.js:19:20)
    at Generator.next (<anonymous>)

Uncaught TypeError: Class constructor Shape cannot be invoked without 'new'

`class Colored {
initializer () { this._color = "white" }
get color () { return this._color }
set color (v) { this._color = v }
}

class ZCoord {
initializer () { this._z = 0 }
get z () { return this._z }
set z (v) { this._z = v }
}

class Shape {
constructor (x, y) { this._x = x; this._y = y }
get x () { return this._x }
set x (v) { this._x = v }
get y () { return this._y }
set y (v) { this._y = v }
}

class Rectangle extends aggregation(Shape, Colored, ZCoord) {}
new Rectangle(5,6)`

Uncaught TypeError: Class constructor Shape cannot be invoked without 'new' at new __Aggregate (aggregation-es6.js:31) __Aggregate @ aggregation-es6.js:31

Maybe you can try to update the code with Reflect?

Just think that ES6 is not trying to use Reflect?

Modified the code

var aggregation = (base, ...mixins) => {
  /*  create aggregation class  */
  let aggregate = class __Aggregate extends base {
    constructor (...args) {
      /*  call base class constructor  */
      super(...args)

      /*  call mixin's initializer  */
      mixins.forEach(mixin => {
        if (typeof mixin.prototype.initializer === 'function') { mixin.prototype.initializer.apply(this, args) }
      })
    }
  }

  /*  copy properties  */
  let copyProps = (target, source) => {
    Reflect.ownKeys(source)
      .forEach(prop => {
        if (
          prop.match(
            /^(?:initializer|constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/
          )
        ) { return }
        Reflect.set(
          target,
          prop,
          Reflect.getOwnPropertyDescriptor(source, prop)
        )
      })
  }

  /*  copy all properties of all mixins into aggregation class  */
  mixins.forEach(mixin => {
    copyProps(aggregate.prototype, mixin.prototype)
    copyProps(aggregate, mixin)
  })

  return aggregate
}

Finally, I feel that Reflect is a bit more interesting, nothing more. o((^โ–ฝ^))o

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.