components icon indicating copy to clipboard operation
components copied to clipboard

Deep components inheritance is likely to break

Open medikoo opened this issue 7 years ago • 0 comments

When initializing component, we create a function on which we assign properties of core component prototype, and of prototype of class of which component we create:

https://github.com/serverless/core/blob/fd9d7460cf8c2fa5decef77178136fd3aa021897/src/Component.js#L35-L61

This works with component class inherits directly from core, but if inheritance tree is deeper (as. e.g. Core -> A -> B, then A specific properties will be missing.

To avoid it, instead of copying properties we may rely on setPrototypeOf and eventually ensure all Function.prototype methods are copied onto result defaultFunction.

Other question is whether there's an advantage of exposing a function. It appears to me, it's used mostly internally. Maybe we can revert from that, and just do typical object instance, then there'll be no need for such hacking

medikoo avatar Oct 28 '19 11:10 medikoo