-
Notifications
You must be signed in to change notification settings - Fork 15
Using ES6 and TypeScript classes as a base #5
Comments
If the goal of compose is to move away from the classical inheritance system, then in my mind at least at seems reasonable to offer limited support for interaction with ES6/Typescript classes. Basically the message would be that compose tries to be compatible with existing code that uses those constructs but it doesn't encourage using them. |
I'm curious to know how the second path could be implemented cleanly. As far as I can tell, classes could only be passed to |
@mwistrand that is the challenge that I have, there could likely be side-effects, which would have to be worked through, but essentially what I was thinking was something that during the mixin process, that an instance of the class would be created, the own properties would be mixed into the prototype and then own properties of the Some considerations are that in ES7, class properties are being proposed. I agree the intent is the class compatibility as a by product, but in certain ways, we should try to may the byproduct as easy (and unsurprising) as possible. One other thought, it is theoretically possible to utilise the Reflect API to detect any class properties that are being passed in and then "throw" (or possibly define them), but that would add runtime overhead to the composition process. |
For now, not considering changes to compose, so it is document and explain behaviour. |
Currently the
create
andmixin
API can accept ES6 and TypeScript classes. There are a few "challenges" with using these, it can especially get confusing with the type inference.At the moment, none of the constructor functions are executed. This was mainly to avoid any unintended consequences of the constructors. In addition, you cannot directly call ES6 constructors without the
new
keyword, meaning that several instances would be created and thrown away during construction.From a disadvantage point, you do not get any of the affects of the constructor. This is very important though when using non-method properties in TypeScript classes as the type inferrance will abstract those properties from the class, but since then TypeScript moves all of that property setting to the constructor on emit, you don't actually get the values defined. For example, this does not work properly with compose:
I see two paths forward:
The text was updated successfully, but these errors were encountered: