I've created a large library in Dart that need to be called from JavaScript. I'd like to avoid using JS Interop if possible. Can I use the Dart Dev Compiler to do this?
Is it possible to take the JavaScript code generated by DDC and easily call it directly?
I'm guessing you'll need some #JS because otherwise, the tree-shaking will likely remove any need for the very entrypoints you want, and the code won't even be there.
Related
In theory it looks like it should be possible. There is: Dart-to-JavaScript compiler and even package to call JS from Dart and opposite.
But I didn't find any resources about it. Did anybody tried? Does anybody knows for sure that it is not possible?
Short answer: maybe, but I seriously doubt it's worth the effort.
To do anything useful with JavaScript, you need to write for a platform like the Web API, node.js, or GNOME in the case of GJS. Dart seems to support the Web API with its web library and its own platform with the vm library.
You might be able to write a transpiler that could transpose from a subset of Dart to GJS, but using any existing dart transpiler is probably impossible.
Suppose I have a global function called foo() which I've implemented internally outside of Lua and exposed to the user. Ideally I'd like the user's IDE to be aware of this function for things like autocomplete. The closest thing that comes to mind would be a header file for C/C++, where the function is declared without being defined.
Does Lua have any support for this?
There is no cross IDE mechanism for this in Lua.
There is no way to declare a function prototype in Lua. You can only define function values. So unless you don't provide your functions as Lua code no IDE will be able to parse them for autocompletion. So you would have to provide IDE-specific autocomplete files for your API.
Most Lua development is probably done in a simple text editor anyway.
Provide a good documentation for your API and any Lua developer using it will be happy.
As Piglet mentioned there is no out-of-the-box solution for Lua that works across all IDEs. However, I found a typed variant of Lua called Teal which has support for declaration files. Teal seems fairly analogous to Typescript.
I'm looking for a framework that will allow me to write a SPA and a embeddable library. I would love to have a way to share component between both. So I'm looking for a solution that has relatively small amount of potential conflicts with other frameworks and with AngularDart it self. Including case when library has been included using script tab, yes two versions of AngularDart on the same page. A framework that has less Global Objects, no Standard Object overrides, no Global Event handling and limited polyfill conflicts.
Dart and AngularDart seams what I need, but I also need more details and docs to validate my assumptions. Anything you are able to point out would be very helpful and greatly appreciated (issues, PR, blogs , roadmap, commits, specs, docs)
It's possible to run multiple AngularDart apps on the same page. I've tested AngularDart todo example app embedded in itself. But I need more details on what dart2js is doing and how compiler avoids global scope pollution.
Yes, AngularDart should be well suited for your requirements.
Dart itself shouldn't pollute your scope at all, you can try running dart2js on something trivial (like just print inside main) and verify the code - it creates a closure and executes it, so nothing inside is accessible from outside. There is also no patching of any global JS objects, so you can run it alongside anything without interference. If it's not the case file a bug.
You can run as many AngularDart applications on a single page as you wish. To get them fully isolated you can compile each one separately with dart2js, then they wouldn't be able to access any of each other internals whatsoever.
When using a third-party JavaScript library in my Dart project, I manually go through the library's documentation and iterate through its properties and methods to build the Dart code through a series of tedious context and callMethod calls. Has anyone figured out a way to automate this?
I tried to first find a command-line interface that introspects the JavaScript library so that I can auto-generate the Dart source code. I've been unsuccessful in my search.
I've tried to make my implementation of .d.ts -> dart2js annotations converter.
This is possible way to automate the process.
Please, see https://github.com/denis-aes/DefinitelyTyped.dart
Introspecting JS lib can be really hard due to the dynamic face of the JS language.
In the Typescript world there are *.d.ts files used to provide types to existing libraries. As far as I can tell most of those files are manually writen.
For now such a tool isn't yet available.
It seems that Dart applications execute their compiled main() function in a thread (isolate) long after the enclosing HTML page has loaded and other scripts on the page have completed. This makes it impossible to inject functions into the document for use by other web components.
e.g. I have UI components that initialize themselves using jquery setup... I'd like to have these UI components delegate to a controller written in dart and this works just fine as long as I set them up in the right order. I could go so far as to call back from dart into JS and run my UI setup but... this is just a bridge to far... (I've already talked myself down from using web components, etc. and resigned myself to using Dart as one big controller of JS functions for now... but if I have to jump through hoops to get even that to work... sigh.)
1) Is there some way to get dart to initialize itself synchronously or to control the initialization process?
2) Is there at least some logical boundary where dart is initializing itself? Some event that I should be targeting for all mysetup after which I know it has run?
Note: this has nothing to do with where the script tag invoking dart is placed or whether it is set to sync or async... Dart seems to spawn an isolate and invoke main() at a later time intentionally.
UPDATE:
It looks like document.ready does fire after main, although I'm not 100% sure it's consistent.
UPDATE 2:
It appears that the packages/browser/dart.js bootstrap loader is causing the delay. I have found that I don't need this and I can simply import the compiled dart js files directly and they work as expected. e.g. if my app is helloworld.dart I can just load and it behaves as expected. Perhaps this should have been obvious, but I had not seen anyone utilize the standalone compiled dart in this way before.
As a bonus I should note that you do not need pub to build these you can just link packages into the source dir and build your JS with dart2js -o outfile. Again, perhaps obvious but without knowing what else the build or bootstrapper does you may not think to try this.