Skip to content

new js interop and commonjs #24722

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

Closed
Aetet opened this issue Oct 24, 2015 · 7 comments
Closed

new js interop and commonjs #24722

Aetet opened this issue Oct 24, 2015 · 7 comments
Assignees
Labels
web-js-interop Issues that impact all js interop

Comments

@Aetet
Copy link

Aetet commented Oct 24, 2015

Currently with new js interop we can load only objects that exists in global. But what about commonjs and es6 module system support? Is it planned to load them?

@zoechi
Copy link
Contributor

zoechi commented Oct 25, 2015

Can you please be more specific about what you want. You can load the modules in JS script tags and instantiate classes from Dart. A concrete example that shows what you try to accomplish would be helpful.

@Aetet
Copy link
Author

Aetet commented Oct 25, 2015

We have library Awesome.
We can load module with js interop if module in global window.Awesome = Awesome;

If module from commonjs-like modules:

var npmModule = require('some-npm-module');

function Awesome() {
   this.obj = npmModule();
}

module.exports = Awesome;

We cannot load it with global require just now. Can js interop support this format of loading modules?

@madsager madsager added the web-js-interop Issues that impact all js interop label Oct 26, 2015
@Aetet
Copy link
Author

Aetet commented Oct 28, 2015

@zoechi Does this example clearify situation?

@zoechi
Copy link
Contributor

zoechi commented Oct 28, 2015

Actually no, not for me, hopefully for the project members.
Why don't you just load it in a JS script tag or using old-style JS-interop?
After it is loaded new JS-interop should work fine.

@Aetet
Copy link
Author

Aetet commented Oct 28, 2015

Because I don't want global variables. I want that all my vars stays local, and not affect global window object. So Commonjs helps keep incapsulation and does not pollute global. Just script tag create all vars global.

@jacob314 jacob314 self-assigned this Oct 28, 2015
@jacob314
Copy link
Member

We don't have any support currently but this is something we will work on supporting in the future.
It is dirty but for now you can work around the lack of support by importing your libraries all under some unlikely to conflict name. For example in JavaScript:
'''
$JS_MODULES_WORKAROUND_931 = {'Awesome': Awesome};
'''
then in dart
''''
@js('$JS_MODULES_WORKAROUND_931.Awesome')
library awesome;

@js('SomeAwesomeClass')
class .... {
}
'''

@jacob314 jacob314 added this to the Later milestone Oct 28, 2015
@jacob314
Copy link
Member

jacob314 commented Jul 8, 2016

Duplicate of #25059

@jacob314 jacob314 closed this as completed Jul 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

4 participants