Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating state fails in Node #123

Closed
taras opened this issue May 28, 2018 · 3 comments
Closed

Creating state fails in Node #123

taras opened this issue May 28, 2018 · 3 comments
Labels

Comments

@taras
Copy link
Member

taras commented May 28, 2018

create(class Foo {}, {}).state throws TypeError: Class constructor Foo cannot be invoked without 'new'. This can be seen in this runkit. The problem seems to stem from the fact that babel can't correctly extend native es6 classes.

This can be easily reproduced by trying microstates in Node.js.

screen shot 2018-05-28 at 8 07 27 am

@taras taras added the bug label May 28, 2018
@taras taras changed the title Creating state fails in Node 6 Creating state fails in Node May 28, 2018
@taras
Copy link
Member Author

taras commented May 28, 2018

It looks like the issue comes down to the fact that babel can't properly extend native classes.

In Babel 7, they introduced a wrapper that can be applied to built-in classes.

screen shot 2018-05-28 at 10 48 41 am

Source: https://medium.freecodecamp.org/were-nearing-the-7-0-babel-release-here-s-all-the-cool-stuff-we-ve-been-doing-8c1ade684039

TypeScript has a proposal to introduce a helper to improve interop with ES5/ES6.

To work around this issue, the users have to either use native classes or babel classes. Which means that if we transpile classes in our library then app classes have to be transpiled. On the flip side, if native ES6 classes are used, then our library has to provide native ES6 classes.

To do this, we can distribute cjs files for Node without transpiling classes. We would only transpile the ES6 modules classes with the assumption that web apps would be transpiled with babel.

There is another alternative which is to remove class from the mechanism that stabilizes classes but I don't know how to achieve the same stable instances without the mechanism that we have.

@cowboyd
Copy link
Member

cowboyd commented Jul 29, 2018

Is this still open?

@cowboyd
Copy link
Member

cowboyd commented Jul 29, 2018

closing unless it's still a problem /cc @taras

@cowboyd cowboyd closed this as completed Jul 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants